Help!

First of all, I’m a complete newb. I’ve been trying to learn php for a total of one week so keep that in mind. I am working on this code and can’t seem to be able to print all of the users information. Can someone give me a suggestion of what I’m doing wrong?

[php]<?php
$userData = array();

$userData[] = array(
‘Name’ => ‘Joe Banks’,
‘Acct’ => ‘12345’,
‘Email’ => ‘[email protected]’,
‘UserName’ => ‘Joe’,
‘Active’ => false);
$userData[] = array(
‘Name’ => ‘Polly Cartwrite’,
‘Acct’ => ‘34567’,
‘Email’ => ‘[email protected]’,
‘UserName’ => ‘PCart’,
‘Active’ => true);
$userData[] = array(
‘Name’ => ‘Jake Jarvis’,
‘Acct’ => ‘81812’,
‘Email’ => ‘[email protected]’,
‘UserName’ => ‘jakej’,
‘Active’ => true);
$userData[] = array(
‘Name’ => ‘Kelly Williams’,
‘Acct’ => ‘76253’,
‘Email’ => ‘[email protected]’,
‘UserName’ => ‘kellyw’,
‘Active’ => false);
$userData[] = array(
‘Name’ => ‘Cindy Ella’,
‘Acct’ => ‘62341’,
‘Email’ => ‘[email protected]’,
‘UserName’ => ‘Cinders’,
‘Active’ => true);
function printUserTable($userData){
foreach($userData as $singleUser){
echo $singleUser;
}
}

		 printUserTable($userData);

?>[/php]

You are using an associative array and not specifying the key to echo.

[php]echo $singleUser[‘Name’];[/php]

You could also loop through each of the user values to output them all. For example:

[php]
foreach($userData as $singleUser) {
foreach($singleUser as $key => $value) {
echo $key . ": " . $value . PHP_EOL;
}
}
[/php]

Oh, I see. Thanks so much!

Sponsor our Newsletter | Privacy Policy | Terms of Service