[PHP] help, array values echoed as Array on loop!

2002-09-02 Thread Victor

I have tried both ways to loop through an array and output the data and
verify that the array is an array and I get no erros but I get this
value, which should not be so.


Here I'm checking if it's an array:

if (!is_array($ID_arr)) { # show error if no array
echo '$ID_arr is not an array.';
}

here I'm counting the keys but it only outputs as 1:

$key = count($ID_arr);
echo $key;

here are two loops that do the same thing and they both output Array:

for($i = 0; $i  count($ID_arr); $i++) {
echo $ID_arr[$i];
}

foreach($ID_arr as $ind_picture) {
echo $ind_picture;
}

Why? If it helps, in order to get the array, the values were taken from
a database and exploded from a coma delimited string.

$ID_arr[] = explode(',', $pictures); # make db data into array

This is the string:

15,16,17,18,19

I want each array element to contain 

= 15 
= 16
= 17
etc...

why does it echo as Array?

- Victor  www.argilent.com


__ 
Post your free ad now! http://personals.yahoo.ca

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] help, array values echoed as Array on loop!

2002-09-02 Thread Chris Wesley

On Mon, 2 Sep 2002, Victor wrote:

 $ID_arr[] = explode(',', $pictures); # make db data into array
 This is the string:
 15,16,17,18,19

 why does it echo as Array?

... because you've created an array ($ID_arr) with an array as the first
value (the result of the call to explode()).  Take the brackets off
$ID_arr, and you'll get what you want.  You don't want your array in an
array ... you just want an array.

$ID_arr = explode(',', $pictures);

If you really wanted your array in the array, then loop over $ID_arr[0].
(I doubt that's what you were going for, though.)

hth,
~Chris



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] help, array values echoed as Array on loop!

2002-09-02 Thread Victor

Thank you, I figured it out 30 seconds after I posted the question, you
were right about the problem.

- Victor  www.argilent.com

-Original Message-
From: Chris Wesley [mailto:[EMAIL PROTECTED]] 
Sent: Monday, September 02, 2002 4:11 PM
To: 'PHP'
Cc: Victor
Subject: Re: [PHP] help, array values echoed as Array on loop!

On Mon, 2 Sep 2002, Victor wrote:

 $ID_arr[] = explode(',', $pictures); # make db data into array
 This is the string:
 15,16,17,18,19

 why does it echo as Array?

... because you've created an array ($ID_arr) with an array as the first
value (the result of the call to explode()).  Take the brackets off
$ID_arr, and you'll get what you want.  You don't want your array in an
array ... you just want an array.

$ID_arr = explode(',', $pictures);

If you really wanted your array in the array, then loop over $ID_arr[0].
(I doubt that's what you were going for, though.)

hth,
~Chris


__ 
Post your free ad now! http://personals.yahoo.ca

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php