Array Help

Discussion in 'PHP' started by jonathandey, Oct 7, 2010.

  1. #1
    
    		$a = explode(", ", $g->readby);
    		$b = explode(", ", $g->view_date);
    		$count = 0;
    			for($i=0;$i<count($a);$i++){
    					foreach($a as $key => $value){
    						
    					}
    					foreach($b as $kat => $vault){
    						$array = ($key => $vault);
    					}
    					print_r($array);
    			}
    
    PHP:
    I'm trying to join the two values from each array in to one, could you tell me why I'm doing this wrong and how to fix it?

    Thanks
     
    jonathandey, Oct 7, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    Maybe you need this one:

    
    $a = explode(", ", $g->readby);
    $b = explode(", ", $g->view_date);
    
    print_r(array_merge($a,$b));
    
    PHP:
     
    s_ruben, Oct 7, 2010 IP
  3. jonathandey

    jonathandey Active Member

    Messages:
    112
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    What I'm trying to do is get the value of readby and make it equal the value of view_date
    e.g
    
    $array = ($readby => $viewdate)
    
    PHP:
     
    jonathandey, Oct 7, 2010 IP
  4. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #4
    Maybe you need this:

    
    $a = explode(", ", $g->readby);
    $b = explode(", ", $g->view_date);
    
    $keys = array_keys($a);
    $values = array_values($b);
    
    $array = array_combine($keys,$values);
    
    print_r($array);
    
    PHP:
    or this:

    
    $a = explode(", ", $g->readby);
    $b = explode(", ", $g->view_date);
    
    $keys = array_values($a);
    $values = array_values($b);
    
    $array = array_combine($keys,$values);
    
    print_r($array);
    
    PHP:
     
    s_ruben, Oct 7, 2010 IP
  5. jonathandey

    jonathandey Active Member

    Messages:
    112
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #5
    Your a life saver! Thanks for the help! :)
     
    jonathandey, Oct 7, 2010 IP