I need to mount an array_multisort with the values from one array.
I tryied to mount a string concated and call on the array_multidimensional like here:
function ordenar_matriz_ultima_posicion_por_distancia($matriz_up,$m_vehiculo_distancias){
$total_vehiculos=count($matriz_up[id_vehiculo]);
//resetear las keys de vehiculos para coger bien los kms y asignarlos
$a_vehiculo_distancia = array_values($m_vehiculo_distancias);
$ordenar = array();
foreach ($a_vehiculo_distancia as $key) {
$ordenar[] = $key;
}
sort($m_vehiculo_distancias);
$string= "";
$ultim_key = end(array_keys($matriz_up));
foreach ($matriz_up as $key => $valor) {
if ($key != $ultim_key) $string.= $matriz_up[$key].',';
else $string.= $matriz_up[$key];
$aaa = '$matriz_up[$key]';
}
echo $string;
echo "<br>";
array_multisort($ordenar, SORT_ASC, $string);
for($i=0;$i<$total_vehiculos;$i++){
$matriz_up['cercanos'][$i] = $m_vehiculo_distancias[$i];
echo $matriz_up['id_vehiculo'][$i]."<br>";
echo $matriz_up['fecha_gps'][$i]."<br>";
echo $matriz_up['id_tipo_posicion'][$i]."<br>";
echo $matriz_up['cercanos'][$i]."<br>";
echo $matriz_up['vaina'][$i]."<br>";
echo "------------<br>";
}
return $matriz_up;
}
$matriz_up['id_vehiculo'][0] = 9;
$matriz_up['fecha_gps'][0] = '2014';
$matriz_up['id_tipo_posicion'][0] = 11111;
$matriz_up['cercanos'][0] = 0;
$matriz_up['vaina'][0] = 12345;
$matriz_up['id_vehiculo'][1] = 3;
$matriz_up['fecha_gps'][1] = '2015';
$matriz_up['id_tipo_posicion'][1] = 22222;
$matriz_up['cercanos'][1] = 0;
$matriz_up['vaina'][1] = 5555;
$matriz_up['id_vehiculo'][2] = 1;
$matriz_up['fecha_gps'][2] = '2016';
$matriz_up['id_tipo_posicion'][2] = 33333;
$matriz_up['cercanos'][2] = 0;
$matriz_up['vaina'][2] = 988;
$matriz_up['id_vehiculo'][3] = 4;
$matriz_up['fecha_gps'][3] = '2017';
$matriz_up['id_tipo_posicion'][3] = 44444;
$matriz_up['cercanos'][3] = 0;
$matriz_up['vaina'][3] = 777;
$m_vehiculo_distancias[9] = 345;
$m_vehiculo_distancias[3] = 712;
$m_vehiculo_distancias[1] = 10;
$m_vehiculo_distancias[4] = 35;
ordenar_matriz_ultima_posicion_por_distancia($matriz_up,$m_vehiculo_distancias);
With this array_multisort works, but i need to take all the key without put manually..
array_multisort($ordenar, SORT_ASC, $matriz_up['id_vehiculo'], $matriz_up['fecha_gps'], $matriz_up['id_tipo_posicion'], $matriz_up['vaina'] );
Try this code:
<?php
$matriz_up = $m_vehiculo_distancias = array();
$matriz_up['id_vehiculo'][0] = 9;
$matriz_up['fecha_gps'][0] = '2014';
$matriz_up['id_tipo_posicion'][0] = 11111;
$matriz_up['cercanos'][0] = 0;
$matriz_up['vaina'][0] = 12345;
$matriz_up['id_vehiculo'][1] = 3;
$matriz_up['fecha_gps'][1] = '2015';
$matriz_up['id_tipo_posicion'][1] = 22222;
$matriz_up['cercanos'][1] = 0;
$matriz_up['vaina'][1] = 5555;
$matriz_up['id_vehiculo'][2] = 1;
$matriz_up['fecha_gps'][2] = '2016';
$matriz_up['id_tipo_posicion'][2] = 33333;
$matriz_up['cercanos'][2] = 0;
$matriz_up['vaina'][2] = 988;
$matriz_up['id_vehiculo'][3] = 4;
$matriz_up['fecha_gps'][3] = '2017';
$matriz_up['id_tipo_posicion'][3] = 44444;
$matriz_up['cercanos'][3] = 0;
$matriz_up['vaina'][3] = 777;
$m_vehiculo_distancias[9] = 345;
$m_vehiculo_distancias[3] = 712;
$m_vehiculo_distancias[1] = 10;
$m_vehiculo_distancias[4] = 35;
function sortArray($arrayToSortParam, $orderArray)
{
$result = array();
$arrayToSort = $arrayToSortParam;
$keys = array_keys($arrayToSort);
asort($orderArray, true);
$newSort = $cercanos = array();
foreach($orderArray as $key => $value)
{
$newSort[] = array_keys($arrayToSort['id_vehiculo'], $key)[0];
$cercanos[] = $orderArray[$key];
}
foreach($keys as $keyName)
{
uksort($arrayToSort[$keyName], function($key1, $key2) use ($newSort) {
return (array_search($key1, $newSort) > array_search($key2, $newSort));
});
}
$arrayToSort['cercanos'] = $cercanos;
//reset indexes
foreach($keys as $keyName)
{
$arrayToSort[$keyName] = array_values($arrayToSort[$keyName]);
}
return $arrayToSort;
}
echo '<pre>';
//print_r($matriz_up);
//print_r($m_vehiculo_distancias);
print_r(sortArray($matriz_up, $m_vehiculo_distancias)); //this is result
Working fiddle: CLICK!
Related
I need to get the minimum value of this array.
I am using array_maps and running it with for and can't find what I want.
$des['PICO']['new'] = 98;
$des['PICO']['old'] = 100;
$des['ALTO']['new'] = 101;
$des['ALTO']['old'] = 110;
$des['BAI']['new'] = 96;
$des['BAI']['old'] = 102;
$min_new = null;
$min_old = null;
$min_key = null;
foreach($des as $key => $value){
if($min_new < $value['new']){
$min_new = $value['new'];
$min_old = $value['old'];
$min_key = $key;
}
}
The main problem is that you are starting your min value at null. This will mean that none of the values are less than that. So start it at the highest int and only store the key value for use later...
$min_new = PHP_INT_MAX;
$min_key = null;
foreach($des as $key => $value){
if($min_new > $value['new']){
$min_new = $value['new'];
$min_key = $key;
}
}
print_r($des[$min_key]);
<?php
$des['PICO']['new'] = 98;
$des['PICO']['old'] = 100;
$des['ALTO']['new'] = 101;
$des['ALTO']['old'] = 110;
$des['BAI']['new'] = 96;
$des['BAI']['old'] = 102;
$min_new = PHP_INT_MAX;
$min_old = PHP_INT_MAX;
$min_key = PHP_INT_MAX;
foreach($des as $key => $value){
if($min_new > $value['new']){
$min_new = $value['new'];
}
if($min_old > $value['old']){
$min_old = $value['old'];
}
if($min_key > $min_new ){
$min_key = $min_new;
}
if($min_key > $min_old ){
$min_key = $min_old;
}
}
echo "n=". $min_new . " o=" . $min_old . " k=" . $min_key;
?>
or
foreach($des as $key => $value){
if($min_new > $value['new']){
$min_new = $value['new'];
$min_key = $key;
}
if($min_old > $value['old']){
$min_old = $value['old'];
$min_key = $key;
}
}
echo "n=". $min_new . " o=" . $min_old . " k=" . $min_key;
Output:
n=96 o=100 k=BAI
Good afternoon, please help me. At me when parsing the result of parsing is not displayed.
link my php file https://dropmefiles.com/cv4Q2
Please correct where I was wrong. Or help to rewrite a little code so that it displays the result of the parser.
Already tried all the options, it does not work in any way. My knowledge here is not enough.
1 file
part 1
function getForecastXML($cid='579432') {
$cid = "579432";
$hoffset = "4";
$appid= "d86ad74d22ce9cc528d8baee65acd408";
$lang= "ru";
$days = array();
$xml = #file_get_contents("http://api.openweathermap.org/data/2.5/forecast?id=$cid&mode=xml&appid=$appid&lang=$lang&type=like");
if ($xml===false) { return;} else {
$xml = simplexml_load_string($xml);
$cityname = (string)$xml->location->name;
$weekdays[0] = "Воскресенье";
$weekdays[1] = "Понедельник";
$weekdays[2] = "Вторник";
$weekdays[3] = "Среда";
$weekdays[4] = "Четверг";
$weekdays[5] = "Пятница";
$weekdays[6] = "Суббота";
if (count($xml->forecast->time)>0){
foreach ($xml->forecast->time as $fpart) {
$forecast = array();
$attr = $fpart->attributes();
$forecast['t']['min'] = (string)round(($fpart->temperature->attributes()->min)-273,15,PHP_ROUND_HALF_UP);
$forecast['t']['min'] = $forecast['t']['min'] > 0 ? "+".$forecast['t']['min'] : $forecast['t']['min'];
$forecast['t']['max'] = (string)round(($fpart->temperature->attributes()->max)-273,15,PHP_ROUND_HALF_UP);
$forecast['t']['max'] = $forecast['t']['max'] > 0 ? "+".$forecast['t']['max'] : $forecast['t']['max'];
$forecast['p']['min'] = (string)round($fpart->pressure->attributes()->value,0,PHP_ROUND_HALF_UP);
// $forecast['p']['max'] = (string)$fpart->PRESSURE->attributes()->max;
$forecast['w']['min'] = (string)round($fpart->windSpeed->attributes()->mps,0,PHP_ROUND_HALF_UP);
//$forecast['w']['max'] = (string)$fpart->WIND->attributes()->max;
//$forecast['w']['rumb'] = (string)$fpart->WIND->attributes()->direction;
$forecast['h']['min'] = (string)$fpart->humidity->attributes()->value;
//$forecast['h']['max'] = (string)$fpart->RELWET->attributes()->max;
$forecast['symb'] = (string)$fpart->symbol->attributes()->name;
$forecast['pict'] = (string)$fpart->symbol->attributes()->var;
$date = date('c',strtotime($hoffset.' hours',strtotime($attr['from'])));
$hour = date('H',strtotime($date));
$forecast['timestamp'] =strtotime($date);
$date = strtotime($date);
$dayofweek = date('w',$date);
$date = $weekdays[$dayofweek]." ".date('d.m',$date);
if ($forecast['timestamp'] > time()){
$days[$date][$hour] = $forecast;
}
}
} else {$days=array();}
}
//return array($cityname,$days);
return [$cityname => $days];
//echo [$cityname => $days];
}
part 2
$outputData = array();
if (count($this->forecast) > 0) {
foreach ($this->forecast as $date => $daypart) {
$outputData[] = $date;
foreach ($daypart as $dp => $data) {
$outputData[] = str_pad($dp, 2, '0', STR_PAD_LEFT);
$outputData[] = $data['symb'];
$outputData[] = $data['t']['min'];
$outputData[] = $data['t']['max'];
if (($data['p']['min']) > 0) {
$outputData[] = "Давление " . round($data['p']['min'] * 0.75006375541921) . "мм. рт. ст.";
}
}
}
} else {
$outputData[] = "В данный момент информация о погоде отсутствует";
}
echo implode(' ', $outputData);
I've read some texts and searched topics, but nothing help me. I'm beginner in PHP. I have array where are variables $qA01_1 up to $qA30_5 and their values can be different 0 or 1 or 5. From array I would like to find all variables with value 1 and make sum. Same for number 5.
$qA01_1 = $_SESSION['qA01_1'];
$qA01_2 = $_SESSION['qA01_2'];
$qA01_3 = $_SESSION['qA01_3'];
$qA01_4 = $_SESSION['qA01_4'];
$qA01_5 = $_SESSION['qA01_5'];
$qA02_1 = $_SESSION['qA02_1'];
$qA02_2 = $_SESSION['qA02_2'];
$qA02_3 = $_SESSION['qA02_3'];
$qA02_4 = $_SESSION['qA02_4'];
$qA02_5 = $_SESSION['qA02_5'];
$qA03_1 = $_SESSION['qA03_1'];
$qA03_2 = $_SESSION['qA03_2'];
$qA03_3 = $_SESSION['qA03_3'];
$qA03_4 = $_SESSION['qA03_4'];
$qA03_5 = $_SESSION['qA03_5'];
$qA04_1 = $_SESSION['qA04_1'];
$qA04_2 = $_SESSION['qA04_2'];
$qA04_3 = $_SESSION['qA04_3'];
$qA04_4 = $_SESSION['qA04_4'];
$qA04_5 = $_SESSION['qA04_5'];
$qA05_1 = $_SESSION['qA05_1'];
$qA05_2 = $_SESSION['qA05_2'];
$qA05_3 = $_SESSION['qA05_3'];
$qA05_4 = $_SESSION['qA05_4'];
$qA05_5 = $_SESSION['qA05_5'];
$qA06_1 = $_SESSION['qA06_1'];
$qA06_2 = $_SESSION['qA06_2'];
$qA06_3 = $_SESSION['qA06_3'];
$qA06_4 = $_SESSION['qA06_4'];
$qA06_5 = $_SESSION['qA06_5'];
$qA07_1 = $_SESSION['qA07_1'];
$qA07_2 = $_SESSION['qA07_2'];
$qA07_3 = $_SESSION['qA07_3'];
$qA07_4 = $_SESSION['qA07_4'];
$qA07_5 = $_SESSION['qA07_5'];
$qA08_1 = $_SESSION['qA08_1'];
$qA08_2 = $_SESSION['qA08_2'];
$qA08_3 = $_SESSION['qA08_3'];
$qA08_4 = $_SESSION['qA08_4'];
$qA08_5 = $_SESSION['qA08_5'];
$qA09_1 = $_SESSION['qA09_1'];
$qA09_2 = $_SESSION['qA09_2'];
$qA09_3 = $_SESSION['qA09_3'];
$qA09_4 = $_SESSION['qA09_4'];
$qA09_5 = $_SESSION['qA09_5'];
$qA10_1 = $_SESSION['qA10_1'];
$qA10_2 = $_SESSION['qA10_2'];
$qA10_3 = $_SESSION['qA10_3'];
$qA10_4 = $_SESSION['qA10_4'];
$qA10_5 = $_SESSION['qA10_5'];
$qA11_1 = $_SESSION['qA11_1'];
$qA11_2 = $_SESSION['qA11_2'];
$qA11_3 = $_SESSION['qA11_3'];
$qA11_4 = $_SESSION['qA11_4'];
$qA11_5 = $_SESSION['qA11_5'];
$qA12_1 = $_SESSION['qA12_1'];
$qA12_2 = $_SESSION['qA12_2'];
$qA12_3 = $_SESSION['qA12_3'];
$qA12_4 = $_SESSION['qA12_4'];
$qA12_5 = $_SESSION['qA12_5'];
$qA13_1 = $_SESSION['qA13_1'];
$qA13_2 = $_SESSION['qA13_2'];
$qA13_3 = $_SESSION['qA13_3'];
$qA13_4 = $_SESSION['qA13_4'];
$qA13_5 = $_SESSION['qA13_5'];
$qA14_1 = $_SESSION['qA14_1'];
$qA14_2 = $_SESSION['qA14_2'];
$qA14_3 = $_SESSION['qA14_3'];
$qA14_4 = $_SESSION['qA14_4'];
$qA14_5 = $_SESSION['qA14_5'];
$qA15_1 = $_SESSION['qA15_1'];
$qA15_2 = $_SESSION['qA15_2'];
$qA15_3 = $_SESSION['qA15_3'];
$qA15_4 = $_SESSION['qA15_4'];
$qA15_5 = $_SESSION['qA15_5'];
$qA16_1 = $_SESSION['qA16_1'];
$qA16_2 = $_SESSION['qA16_2'];
$qA16_3 = $_SESSION['qA16_3'];
$qA16_4 = $_SESSION['qA16_4'];
$qA16_5 = $_SESSION['qA16_5'];
$qA17_1 = $_SESSION['qA17_1'];
$qA17_2 = $_SESSION['qA17_2'];
$qA17_3 = $_SESSION['qA17_3'];
$qA17_4 = $_SESSION['qA17_4'];
$qA17_5 = $_SESSION['qA17_5'];
$qA18_1 = $_SESSION['qA18_1'];
$qA18_2 = $_SESSION['qA18_2'];
$qA18_3 = $_SESSION['qA18_3'];
$qA18_4 = $_SESSION['qA18_4'];
$qA18_5 = $_SESSION['qA18_5'];
$qA19_1 = $_SESSION['qA19_1'];
$qA19_2 = $_SESSION['qA19_2'];
$qA19_3 = $_SESSION['qA19_3'];
$qA19_4 = $_SESSION['qA19_4'];
$qA19_5 = $_SESSION['qA19_5'];
$qA20_1 = $_SESSION['qA20_1'];
$qA20_2 = $_SESSION['qA20_2'];
$qA20_3 = $_SESSION['qA20_3'];
$qA20_4 = $_SESSION['qA20_4'];
$qA20_5 = $_SESSION['qA20_5'];
$qA21_1 = $_SESSION['qA21_1'];
$qA21_2 = $_SESSION['qA21_2'];
$qA21_3 = $_SESSION['qA21_3'];
$qA21_4 = $_SESSION['qA21_4'];
$qA21_5 = $_SESSION['qA21_5'];
$qA22_1 = $_SESSION['qA22_1'];
$qA22_2 = $_SESSION['qA22_2'];
$qA22_3 = $_SESSION['qA22_3'];
$qA22_4 = $_SESSION['qA22_4'];
$qA22_5 = $_SESSION['qA22_5'];
$qA23_1 = $_SESSION['qA23_1'];
$qA23_2 = $_SESSION['qA23_2'];
$qA23_3 = $_SESSION['qA23_3'];
$qA23_4 = $_SESSION['qA23_4'];
$qA23_5 = $_SESSION['qA23_5'];
$qA24_1 = $_SESSION['qA24_1'];
$qA24_2 = $_SESSION['qA24_2'];
$qA24_3 = $_SESSION['qA24_3'];
$qA24_4 = $_SESSION['qA24_4'];
$qA24_5 = $_SESSION['qA24_5'];
$qA25_1 = $_SESSION['qA25_1'];
$qA25_2 = $_SESSION['qA25_2'];
$qA25_3 = $_SESSION['qA25_3'];
$qA25_4 = $_SESSION['qA25_4'];
$qA25_5 = $_SESSION['qA25_5'];
$qA26_1 = $_SESSION['qA26_1'];
$qA26_2 = $_SESSION['qA26_2'];
$qA26_3 = $_SESSION['qA26_3'];
$qA26_4 = $_SESSION['qA26_4'];
$qA26_5 = $_SESSION['qA26_5'];
$qA27_1 = $_SESSION['qA27_1'];
$qA27_2 = $_SESSION['qA27_2'];
$qA27_3 = $_SESSION['qA27_3'];
$qA27_4 = $_SESSION['qA27_4'];
$qA27_5 = $_SESSION['qA27_5'];
$qA28_1 = $_SESSION['qA28_1'];
$qA28_2 = $_SESSION['qA28_2'];
$qA28_3 = $_SESSION['qA28_3'];
$qA28_4 = $_SESSION['qA28_4'];
$qA28_5 = $_SESSION['qA28_5'];
$qA29_1 = $_SESSION['qA29_1'];
$qA29_2 = $_SESSION['qA29_2'];
$qA29_3 = $_SESSION['qA29_3'];
$qA29_4 = $_SESSION['qA29_4'];
$qA29_5 = $_SESSION['qA29_5'];
$qA30_1 = $_POST['qA30_1'];
$qA30_2 = $_POST['qA30_2'];
$qA30_1 = (isset($_POST['qA30_1'])) ? $_POST['qA30_1'] : 0;
$qA30_2 = (isset($_POST['qA30_2'])) ? $_POST['qA30_2'] : 0;
$qA30_3 = (isset($_POST['qA30_3'])) ? $_POST['qA30_3'] : 0;
$qA30_4 = (isset($_POST['qA30_4'])) ? $_POST['qA30_4'] : 0;
$qA30_5 = (isset($_POST['qA30_5'])) ? $_POST['qA30_5'] : 0;
Here is my proposal which do not work. I thing that I should to do something with "array" .
// Sum of all numbers 1
$sumOne = 0;
for ($i = 0; $i <= 3; $i++) {
for($j = 0; $j <= 9; $j++) {
for($k = 1; $k <= 5; $k++){
$u = 'qA_' . $i . $j. '_' . $k;
if ($u==1){
$sumOnet+=1;
}
}
}
}
echo "<br/>SumOne:" . " " . round($sumOne[0], 0);
You really should stick with an array. If you define an array within the $_SESSION array and use that it will be much simpler:
$_SESSION['data']['qA01_1'] = 0;
$_SESSION['data']['qA01_2'] = 1;
$_SESSION['data']['qA01_3'] = 5;
$counts = array_count_values($_SESSION['data']);
if(isset($counts[0])) { echo $counts[0]; } // sum of any 0s is 0 so here is the count
if(isset($counts[1])) { echo $counts[1]; } // sum of any 1s will be the count
if(isset($counts[5])) { echo $counts[5] * 5; }
If I understand the question correctly, you want to sum up all individual values in your array.
You can use array_count_values() for that, it returns you the number of occurances of each value where the value itself is the key:
foreach (array_count_values($_SESSION) as $value => $count) {
echo 'sum of ' . $value . ' values: ' . ($value * $count) . "<br>";
}
No idea where the POST variables fit in though...
i want to remove the data from the array when there profile_id duplicate.
this is my array
$response[0]['profile_id'] = 100;
$response[0]['profile_name'] = 'deepu';
$response[0]['address'] = 'deesdvsdvsdvpu';
$response[1]['profile_id'] = 101;
$response[1]['profile_name'] = 'deepu';
$response[1]['address'] = 'deesdvsdvsdvpu';
$response[2]['profile_id'] = 100;
$response[2]['profile_name'] = 'deepu';
$response[2]['address'] = 'deesdvsdvsdvpusdvsdvsdvsdvsdv';
$response[3]['profile_id'] = 102;
$response[3]['profile_name'] = 'desdvsdvepu';
$response[3]['address'] = 'deesdvsdvsdvpusdvsdvsdvsdvsdsdvsdvv';
$input = array_map("unserialize", array_unique(array_map("serialize", $response)));
i want this output
$response[0]['profile_id'] = 100;
$response[0]['profile_name'] = 'deepu';
$response[0]['address'] = 'deesdvsdvsdvpu';
$response[1]['profile_id'] = 101;
$response[1]['profile_name'] = 'deepu';
$response[1]['address'] = 'deesdvsdvsdvpu';
$response[3]['profile_id'] = 102;
$response[3]['profile_name'] = 'desdvsdvepu';
$response[3]['address'] = 'deesdvsdvsdvpusdvsdvsdvsdvsdsdvsdvv';
But I can't get this. If anyone knows about this please help me.
Try the php-function: array_unique
Or manual:
$ids = array();
foreach($response as $key => $entry){
if(in_array($entry['profile_id'], $ids)){
unset($response[$key]);
}else{
$ids[] = $entry['profile_id'];
}
}
$new_arr = array_reduce($response, function($t, $v) {
$profile_id = $v['profile_id'];
if (!isset($t[$profile_id]))
$t[$profile_id] = $v;
return $t;
}, array());
$new_arr = array_values($new_arr); // to get indexes back to 0, 1, 2...
I'm using this code:
$permissions = array("canview", "canpostthreads", "canpostreplies", "canpostpolls", "all");
foreach($permissions as $permission) {
for ($i = 1; $i <= 5; $i++) {
$mode = $_POST['permission'][$i][$permission];
if($mode == 1)
echo "{$permission} = {$i}:::";
}
}
And the output if I check some checkboxes is:
canview = 1:::canview = 5:::canpostreplies = 3:::canpostpolls = 5:::
I wan't the output to be following:
instead of canview = 1:::canview = 5:
canview = 1,5
and if I'll have for example:
canpostpolls = 1:::canpostpolls = 2:::canpostpolls = 3
It'll be:
canpostpolls = 1,2,3:::canview = 1,5
I hope you understand it guys. This is my own idea for this, you are free to share your ideas with me, this data will be exported to the mysql table.
$permissions = array("canview", "canpostthreads", "canpostreplies", "canpostpolls", "all");
$setpermissions = array();
foreach($permissions as $permission) {
for ($i = 1; $i <= 5; $i++) {
$mode = $_POST['permission'][$i][$permission];
if($mode == 1) {
if (!isset($setpermissions[$permission])) {
$setpermissions[$permission] = array();
}
$setpermissions[$permission][] = $i;
}
}
}
$plist = array();
foreach ($setpermissions as $name => $sp) {
$plist[] = "$name = " . implode(',', $sp);
}
echo implode(':::', $plist);
You need to filter your data a bit more... maybe something like this:
$permissions = array("canview", "canpostthreads", "canpostreplies", "canpostpolls", "all");
$filtered_perms = array();
foreach($permissions as $permission) {
for ($i = 1; $i <= 5; $i++) {
$mode = $_POST['permission'][$i][$permission];
if($mode == 1) {
if(!is_array($filtered_perms[$permission])) {
$filtered_perms[$permission] = array();
}
$filtered_perms[$permission][] = $i;
}
}
Then, you can do something like:
$final_perms = array();
foreach($filtered_perms as $key => $val) {
$final_perms[$key] = implode(",", $val);
}
Hope that helps!
$permissions = array("canview", "canpostthreads", "canpostreplies", "canpostpolls", "all");
$userPermissions = array();
foreach($permissions as $permission) {
for ($i = 1; $i <= 5; $i++) {
$mode = $_POST['permission'][$i][$permission];
if($mode == 1)
$userPermissions[$permission][] = $i;
}
}
foreach($userPermissions as $permission => $values) {
echo "{$permission} = " . implode(',', $values) . ":::";
}
You can do something like this - essentially, combining the values before outputting them.
$permissions = array("canview", "canpostthreads", "canpostreplies", "canpostpolls", "all");
foreach($permissions as $permission) {
$vals = array();
for ($i = 1; $i <= 5; $i++) {
$mode = $_POST['permission'][$i][$permission];
if($mode == 1)
$vals[] = $i;
}
if(count($vals))
echo $permission . ' == ' . implode(',', $vals);
}