FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP Array, explode, count , access array problem.





flatliner
Hi guys
I don't what the hell is up with this, but the snippet of code below doesn't work from some unknown reason. I have seached around php manual and nothing documenting that you cannot use the value of a count() function as a key to access an array.

Any idea's?

Code:


$string = "joe.john.james";

  $my_array = explode(".", $string);// breaks up string into an array
  $x = count($my_array); // Counts the number in array

echo $my_array[$x];// Nothing is displayed
echo $x // the value is displayed as been 3 which is correct

leontius
I haven't checked the code really, but I think in your case $x has the value of 3. Array index starts with 0, so $string[3] has no value. ($string[0] = 'joe', $string[1] = 'john', $string[2] = 'james').
flatliner
leontius wrote:
I haven't checked the code really, but I think in your case $x has the value of 3. Array index starts with 0, so $string[3] has no value. ($string[0] = 'joe', $string[1] = 'john', $string[2] = 'james').


Oh my god your right, its to early in the morning for me ha. Its always somthing so simple like that.
Thanks a million man.
Related topics
PHP FUSION
PHP Help Needed
Login Scripts
create a page of access in PHP?
PHP script has MSQL access denied
Php - Basic Encryption site
[PHP] Faking Shell Access Through PHP
[php] array reference
access active directory ldap server with php
php array() problem
directory access problem
displaying from array
Problem with galary script
counting the unique word frequencies
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.