Treating array_count_values as an array
Posted: Sun May 25, 2008 6:46 am
I'm having trouble understanding why I can't treat a function which returns an array as an array.
Take the following example
This produces the error "Parse error: syntax error, unexpected '[' in /var/www/test.php on line XX"
Yet if I adjust it to say...
Why is this the case?
Take the following example
Code: Select all
$names = array("dan", "david", "john", "dan", "clive", "david", "david", "steve");
$namecount = array_count_values($names)["david"];
print "<p>David appears $namecount times.</p>"; Yet if I adjust it to say...
Code: Select all
$names = array("dan", "david", "john", "dan", "clive", "david", "david", "steve");
$namecountarray = array_count_values($names);
$namecount = $namecountarray["david"];
print "<p>The name david appears $namecount times.</p>";