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
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));
?> 

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.