instead of foreach and for

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
greennjk
Forum Newbie
Posts: 2
Joined: Tue Jul 15, 2008 11:44 pm

instead of foreach and for

Post by greennjk »

Hi to all,

I have two arrays . One array contains field name and another one contain field values. I want make condition "fieldname = fieldvalue" . Is there any PHP built in function available for achieve this?

ex: array1('fieldname1','fieldname2');
array2('fieldvalue1','fieldvalue2');

I want to make "fieldname1 = fieldvalue1, fieldname2 = fieldvalue2". want to just add = between two array values. I dont want to use foreach or for loop for extract array values and concatenate = symbol with aarray value. Is there any PHP built in function available, please send it to this forum..
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: instead of foreach and for

Post by Benjamin »

I'm not sure why you want to avoid foreach but this will do it.

Code: Select all

 
function concat($x, $y)
{
    return "$x = $y";
}
 
$concated = array_map('concat', range(1,5), range(6, 10));
 
echo "<pre>" . print_r($concated, true) . "</pre>";
 
greennjk
Forum Newbie
Posts: 2
Joined: Tue Jul 15, 2008 11:44 pm

Re: instead of foreach and for

Post by greennjk »

Thanks astian..
Post Reply