Click to See Complete Forum and Search --> : add $var's to new array


Bungholio
06-30-2003, 03:49 PM
Hi, thanks for looking,

ok a little bit of nfo before i get to my problem, there are images in 'images/' like so;

39_images01.jpg
39_images02.jpg
40_you are crazy.jpg
40_one-two.jpg

ok so, i have the following code;


function MainPic($GID) {
$handle = opendir("images");
while ($file = readdir($handle)) {
if ($file != "." && $file != ".."){
$array = split("_",$file);
if ($array[0] == $GID){
echo ($file."<br>\n");
}
}
}
closedir($handle);
}



so if you can imagine i call my function like;

$GID="39";
MainPic($GID);

then im going to get a list of the images (from above)

39_images01.jpg
39_images02.jpg

right? ... ok, so instead of echoing the files, i would like to put them into an array, because im going to use array_rand in the future to display a random image for the appropriate $GID call :) .. can any help me with this? I checked the array section on php.net and didnt see any examples of creating arrays with adding $file ..
any ideas?

Thanks a bunch,
Al

Jona
06-30-2003, 04:25 PM
You should use array_push() (http://us3.php.net/array_push) to append values to an array.

[J]ona

pyro
06-30-2003, 10:38 PM
You'll find a full list of array commands at http://us3.php.net/array, including array_push() (http://us3.php.net/manual/en/function.array-push.php) as Jona mentioned, and array_unshift() (http://us3.php.net/manual/en/function.array-unshift.php) to prepend values to the beginning of an array.

Bungholio
07-01-2003, 10:06 AM
thanks fellas

Jona
07-01-2003, 11:04 AM
Well, for what I did, you're welcome. (I'm not gonna speak for pyro, he knows too much as it is. :D)

[J]ona

pyro
07-01-2003, 11:06 AM
lol.. and I always feel bad saying "Your welcome" if I the help was mutually offered, as I feel like I'm saying to the other poster "Hey look, he said thank you, and it must have been to me..." :D That's just me, I guess... Anyway, for my part, you're welcome... ;)

Jona
07-01-2003, 11:08 AM
Didn't mean to bring on the guilt... :p

[J]ona

pyro
07-01-2003, 11:09 AM
hehe... nope, no guilt. Just saying why I didn't acknowledge it. :)