for loop problem

Discussion in 'PHP' started by Ntech, Sep 5, 2009.

  1. #1
    Given this array:

    $categories = array(4,15,21,83,122);

    the following for loop should be replacing the number 15 with the number 0 but instead it's replacing all the numbers with 0.

    
    $n = count($categories);
    	
    for($i=0; $i<$n; $i++)
    {
    	if ($categories[$i] = 15)
    	{
    		$categories[$i] = 0;
    	}
    }
    
    Code (markup):
    I'm at a loss to figure this out.
     
    Ntech, Sep 5, 2009 IP
  2. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if ($categories[$i] == 15)
    PHP:
     
    szalinski, Sep 5, 2009 IP
  3. Ntech

    Ntech Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ah hell!

    I can't tell you how long I've stared at that piece of code and that never occurred to me.

    Thanks szalinski, now I can move on to my next obvious bug.
     
    Ntech, Sep 5, 2009 IP