|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
||||
|
||||
|
How do I use 1 array to get values from another?
Hello all!
PHP not-so-newbie here! I've got two arrays. One array holds numeric values that I want to correspond with the numeric position of text values in another array - i.e.: $array1 = array(0, apples, oranges, pears, grapes, bananas, peaches); $array2 = array(2, 4, 5); I would like to arrive at this result: $newarray-or-string = (oranges, grapes, bananas); any suggestions? tia - Greg
__________________
$mybrain = "mush"; ------------------------------------------- http://www.loftsboston.com http://www.gregdawsondesign.com |
|
#2
|
|||
|
|||
|
PHP Code:
Not tested... Have a look at the array functions on php.net. There are 2 interesting ones called array_intersect and array_intersect_assoc, which might achieve what you are trying to do more directly. Not sure what your actual application is, though. |
|
#3
|
||||
|
||||
|
Hey, avit! Thanks for the response!
Close, but not quite! Your code returns the correct keys, but in a format that I cannot use (I just need the values): Array ( [Finnish] => [German] => [Italian] => ) I've looked at php.net - array_intersect and array_intersect_assoc do look as though they might apply. Is there any one who is familiar with these? |
|
#4
|
|||
|
|||
|
Simple, change one line:
PHP Code:
|
|
#5
|
||||
|
||||
|
I am now an avid avit fan!
Dude, you are the man, thanks! |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > How do I use 1 array to get values from another? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|