Jump to content

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/298674-create-a-multidimensional-array/
Share on other sites

<?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 by benanamen
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.