note 75427 added to ref.array

From: Date: Tue, 29 May 2007 21:57:32 +0000
Subject: note 75427 added to ref.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-127001@lists.php.net to get a copy of this message
<?php /* This function allow you to transform a multidimensional array in a simple monodimensional array. Usage: array_walk($oldarray, 'flatten_array', &$newarray); For example, this code below shows to you: Array ( [1] => Array ( [0] => 1 [1] => 2 ) [2] => Array ( [0] => 3 [1] => 4 ) ) Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) */ function flatten_array($value, $key, &$array) { if (!is_array($value)) array_push($array,$value); else array_walk($value, 'flatten_array', &$array); } $oldarray = array( 1 => array(1,2), 2 => array(3,4) ); $newarray = array(); array_walk($oldarray, 'flatten_array', &$newarray); echo "<pre>"; print_r($oldarray); print_r($newarray); echo "</pre>"; ?> ---- Server IP: 213.92.11.19 Probable Submitter: 81.174.2.250 ---- Manual Page -- http://www.php.net/manual/en/ref.array.php Edit -- https://master.php.net/note/edit/75427 Del: integrated -- https://master.php.net/note/delete/75427/integrated Del: useless -- https://master.php.net/note/delete/75427/useless Del: bad code -- https://master.php.net/note/delete/75427/bad+code Del: spam -- https://master.php.net/note/delete/75427/spam Del: non-english -- https://master.php.net/note/delete/75427/non-english Del: in docs -- https://master.php.net/note/delete/75427/in+docs Del: other reasons-- https://master.php.net/note/delete/75427 Reject -- https://master.php.net/note/reject/75427 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#127001) next »