Re: Adding the array in to each element of another one array
| From: | Jim Lucas | Date: | Fri, 06 Jul 2007 07:09:05 +0000 |
| Subject: | Re: Adding the array in to each element of another one array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-258398@lists.php.net to get a copy of this message | ||
sivasakthi wrote:
Hi Guys, I have a array like that below, $values = ("name1 %we %tr ", "name2 %de.%ty %sd", "name3 %we 5te %mt/% Hs"); another one array like that, $tmp = ("%tr", "%uy", "%xc"); I need to add the array of $tmp in to each element of array $values.....Also i need to add the $tmp array in to after the name of each element.. could you help me to find the solution..?? Thanks, well, if I understand what you are asking to do, it should be as simple as this.<?php $values[] = "name1 %we %tr "; $values[] = "name2 %de.%ty %sd"; $values[] = "name3 %we 5te %mt/% Hs"; $tmp[] = "%tr"; $tmp[] = "%uy"; $tmp[] = "%xc"; foreach ( $values AS $k => $v ) { if ( isset( $tmp[$k] ) ) {
$values[$k] = $v . $tmp[$k]; // This puts it on the end
$values[$k] = $tmp[$k] . $v; // This puts it at the start
}
}
print_r($values);
?>
Hope this helps
Jim Lucas