php - Display arrays in same order with whitespaces -
i'm having problems display 2 arrays concrete structure, don't know if possible.. have 2 arrays multidimensional
$a
array ( [0] => array ( [id] => 1 [total] => 4 [label] => 1 [url] => 0 ) [1] => array ( [id] => 2 [total] => 2 [label] => 2 [url] => 500 ) [2] => array ( [id] => 3 [total] => 9 [label] => 3 [url] => -100 ) [3] => array ( [id] => 5 [total] => 15 [label] => 5 [ten] => 100 ) )
$b
array ( [0] => array ( [id] => 1 [total] => 2 [label] => 1 [url] => 100 ) [1] => array ( [id] => 4 [total] => 4 [label] => 4 [url] => -100 ) [2] => array ( [id] => 3 [total] => 1 [label] => 3 [url] => 200 ) [3] => array ( [id] => 5 [total] => 1 [label] => 5 [ten] => -100 ) ) [4] => array ( [id] => 7 [total] => 1 [label] => 7 [ten] => 500 ) ) [5] => array ( [id] => 6 [total] => 1 [label] => 6 [ten] => 200 ) )
and want structure listing arrays label
$a $b --- --- 1 1 2 - 3 3 - 4 5 5 - 6 - 7
it's possible?
thanks in advance
first need sort array id
value using array_multisort
that
// define test array $array = array( 0 => array( "id" => 1, "total" => 4, "label" => "one", "url" => 0 ), 1 => array( "id" => 7, "total" => 10, "label" => "seven", "url" => 0 ), 2 => array( "id" => 2, "total" => 13, "label" => "two", "url" => 0 ) ); // "id" list array $ids = array(); foreach ($array $key => $row) { $ids[$key] = $row['id']; }
result :
array (size=3) 0 => array (size=4) 'id' => int 1 'total' => int 4 'label' => string 'one' (length=3) 'url' => int 0 1 => array (size=4) 'id' => int 2 'total' => int 13 'label' => string 'two' (length=3) 'url' => int 0 2 => array (size=4) 'id' => int 7 'total' => int 10 'label' => string 'seven' (length=5) 'url' => int 0
for display, need loop , check if node $findidnode["id"] == $i
exist.
// display result for($i=1; $i<=end($array)["id"]; $i++) { // check if "id" value exist in $array $findidnode = $array[array_search($i, array_column($array, "id"))]; if($findidnode["id"] == $i) echo $findidnode["label"]."<br />"; else echo "-<br />"; }
result :
one 2 - - - - 7
hope help.
Comments
Post a Comment