Jump to content

Help! Am i on the right path???


loudog

Recommended Posts

hey guy's

Im having trouble with writing my own function for array_flip. What im trying to get the same output that the original array_flip does but im not sure if im on the right direction. Here is what i got so far. Plz keep in mind im a  newbie. :P

                                                                                                                                                          thanks in advance.

<?php
function dz_flip($trans){

$temp=array("a"=>0,"b"=>1,"c"=>2);
$arr='';
for($i=-1; $i<$temp; $i--){
 $arr.=$temp[$i];
 $temp=array_flip($trans);
}	
  
return $temp;	
}

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/243561-help-am-i-on-the-right-path/
Share on other sites

Alright guy's,  I think just got me into a situation here. I was able to flip them around with out using the array_flip function but here is the situation. i get both array's the  regular and the flip one now i just don't know how to get rid of the regular one and just keep the  array that i flip. :-\ Here is the code.

 

                                                                                                                                                                        thanks in advance.

 

 

<?php

 

 function dz_flip($temp){

/*$arr='';
for($i=0; $i>$temp; $i--){
 $arr.=$temp[$i];
}*/	
    
  foreach($temp as $key => $value){
    $temp[$value]=$key;
    
}  return $temp;	

The output is this Array ( [horse] => 1 [cat] => 2 [dog] => 3 [1] => horse [2] => cat [3] => dog ) 
}
$temp=array("horse"=>1,"cat"=>2,"dog"=>3);
print_r (dz_flip($temp));
//print_r(array_flip($temp));
?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.