Jump to content

Array Push Error but I've declared Globals


emilyfrazier

Recommended Posts

Hi,

I am getting an error about array push, but I've declared my global variables. The error I get is:

[color=red]warning: array_push() [function.array-push]: First argument should be an array in /home/retnkes9/public_html/drupal/themes/retn/page.tpl.php on line 18.[/color]

Here is my code:
[code]<?php function getRandomImages($count = 1){
global $randomImages;
srand((float) microtime() * 10000000);
$ret = array();
global $ret;
$keys = array_rand($randomImages, $count);
foreach( $keys as $index ){
array_push( $ret, $randomImages[$index] );
}
return  $ret;
}

$randomImages = array();
function addRandomImage( $img = false ) { if( $img ){
global $randomImages;
array_push( $randomImages, $img );
}}
for( $i=1; $i<41; $i++ ){
addRandomImage( "../../../images/random_".sprintf("%02d", $i).".jpg" );
}

?>

<table border="0" cellpadding="0" cellspacing="0" id="header">
  <tr>
   
  <?php
$randomImages = getRandomImages(5);
$first = true;
foreach( $randomImages as $image ){
?>
<?php if( $first ){ $first=false; } else{ ?><td width="16">
<img src="../../../images/randompic_divider.gif" width="16" height="52"></td><?php } ?>
    <td width="52"><img src="<?php echo $image; ?>" width="52" height="52"></td>   
<?php } ?>
    [/code]

I would really appreciate any help on this in advance. It's really messing with me!

Thanks,
Emily
Link to comment
Share on other sites

Hmm. Just tried that, but it didn't change anything. Am still getting the same errors.

Here is my code:[code] <?php
function getRandomImages($count = 1){
global $randomImages;
srand((float) microtime() * 10000000);
$ret = array();
$keys = array_rand($randomImages, $count);
foreach( $keys as $index ){
array_push( $ret, $randomImages[$index] );
}
return  $ret;
}

$randomImages = array();

function addRandomImage( $img = false ) { if( $img ){
global $randomImages;
array_push( $randomImages, $img );
}}
for( $i=1; $i<41; $i++ ){
addRandomImage( "../../../images/random_".sprintf("%02d", $i).".jpg" );
}

?>


<table border="0" cellpadding="0" cellspacing="0" id="header">
  <tr>
 
   
  <?php
$randomImages = getRandomImages(5);
$first = true;
foreach( $randomImages as $image ){
?>
<?php if( $first ){ $first=false; } else{ ?><td width="16">
<img src="../../../images/randompic_divider.gif" width="16" height="52"></td><?php } ?>
    <td width="52"><img src="<?php echo $image; ?>" width="52" height="52"></td>   
<?php } ?>[/code]

Thanks for helping!
Emily
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.