Re: Adding the array in to each element of another one array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux