Am I Missing Something? Array values are not displaying?

Discussion in 'PHP' started by mistergin, Feb 27, 2007.

  1. #1
    I wonder if it's an issue of syntax somewhere. The code renders and outputs ok, but the php array values don't.


    
    function convert_ad_code($text) {
            include 'file that has ad_randoms, ad_title, and ad_body arrays';
    
    	$output = '';
    	
    	$ad_var = "<div class='adv_div'>";
    	
    	for ($tempIncVar = 0; $tempIncVar < 5; $tempIncVar++){
    		$ad_var = $ad_var . "<b>" . $ad_title[$ad_randoms[$tempIncVar]] . "</b><br>" . $ad_body[$ad_randoms[$tempIncVar]] . "<br><br>";
    	}
    
    	$ad_var = $ad_var . "</div>";
    	
    	$output = str_replace("###replaceme###",$ad_var,$text);
    	
    	return $output;
    }
    
    Code (markup):
    It ends up returning this:

    
    <div class="adv_div">
    <b></b><br><span></span><br><br>
    <b></b><br><span></span><br><br>
    <b></b><br><span></span><br><br>
    <b></b><br><span></span><br><br>
    <b></b><br><span></span><br><br>
    </div>
    
    Code (markup):
    The array values never get shown :( I know that the include file is working, after working through a few errors, so the arrays are there.. I just don't know what I'm doing wrong regarding getting them to output.

    Any ideas?
     
    mistergin, Feb 27, 2007 IP
  2. Aragorn

    Aragorn Peon

    Messages:
    1,491
    Likes Received:
    72
    Best Answers:
    1
    Trophy Points:
    0
    #2
    What are $ad_title and $ad_randoms? Are you sure that the values in $ad_randoms are not crossing the array index boundary? Are you sure that $ad_title is defined?
     
    Aragorn, Feb 27, 2007 IP
  3. hemolack

    hemolack Guest

    Messages:
    31
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Try using print_r($ad_title); to see if there is anything at all in the variable.
     
    hemolack, Feb 28, 2007 IP
  4. Synch

    Synch Peon

    Messages:
    76
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    $ad_title[$ad_randoms[$tempIncVar]]

    is $ad_randoms[$tempIncVar] an array inside of ad_title, or is it a 3d array which would be like $ad_title[$ad_randoms][$tempIncBar]. Its hard to tell without seeing the included file.
     
    Synch, Mar 1, 2007 IP