Array
(
[1] => Array
(
[0] => 1
[1] => none
[2] => none
)
[2] => Array
(
[0] => none
[1] => 2
[2] => none
)
[3] => Array
(
[0] => none
[1] => 2
[2] => 3
)
)
Hello experts i have this array from check boxe开发者_开发技巧s and i want to echo it by index values i.e. in order of keys like all 0 index values in one pocket and 1 index values in one pocket for example [[0, 0, 0], [1, 1, 1], [2, 2, 2]] with its values like [[1, none, none], [none, 2, 2], [none, none, 3]]
Please can somebody help me ?
$myArray = array( 1 => array( 0 => 1, 1 => "none", 2 => "none"),
2 => array( 0 => "none", 1 => 2, 2 => "none"),
5 => array( 0 => "none", 1 => 2, 2 => 3) );
$newArray = array();
foreach( $myArray AS $masterIndex => $childArray )
{
foreach( $childArray AS $index => $value )
{
if( !isset($newArray[$index]) )
{
$newArray[$index] = array();
}
$newArray[$index][] = $value;
}
}
$outputValues = "[";
foreach( $newArray AS $childArray )
{
$outputValues .= "[" . implode(",", $childArray) . "],";
}
$outputValues = substr($outputValues, 0, strlen($outputValues) -1) . "]";
echo $outputValues;
That is slightly refined version, with 'implode' instead of another loop...
精彩评论