jacob1986 Posted October 18, 2015 Share Posted October 18, 2015 I have to complete a multidimensional array, I have written PHP code but I keep getting numbers ontop of the arrays? Moreover; could you give me feedback on the multidimensional array is it anygood? <?php $customers = array( $customers =['Name' => 'Bob','id' => '587','Date' => '17/10/1015',], $customers =['Name' => 'Stu','id' => '100','Date' => '02/04/2010', ], $customers =['Name' => 'Kate','id' => '12','Date' => '09/12/2013',], ); $keys = array_keys($customers); $keys = array_keys($customers); for($i = 0; $i < count($customers); $i++) { echo $keys[$i] . "<br>"; foreach($customers[$keys[$i]] as $key => $value) { echo $key . " : " . $value . "<br>";} echo "<br>";} ?> //Ouput: 0Name : Bobid : 587Date : 17/10/1015 1Name : Stuid : 100Date : 02/04/2010 2Name : Kateid : 12Date : 09/12/2013 Quote Link to comment Share on other sites More sharing options...
benanamen Posted October 18, 2015 Share Posted October 18, 2015 (edited) <?php $customers = array( array( 'Name' => "Bob", 'id' => 5, 'date' => '17/10/1015' ), array( 'Name' => "Jim", 'id' => 8, 'Date' => '02/04/2010' ), array( 'Name' => "Sally", 'id' => 3, 'Date' => '09/12/2013' ) ); foreach ($customers as $key => $value) { foreach ($value as $k => $v) { echo "$k = $v\n"; } } ?> Is it any good? It is if you need it. Edited October 18, 2015 by benanamen Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.