1

Friends . Read full details to understand problem.

 av = array("$a1","$a2","$a3"); //  used here loop for that to create auto varibles

 av[i] = $_POST("***"); // something code ...which assign values to array   using loop

 echo " $a1 $a2  " // its display correct value

now my problem is

i want to copy all array variables av values to var array vaiables.

var array consist variables like " $a1 " many times.

             var = array("$a1","$a1","$a1","$a2","$a2","$a3");

var array consist defined order . i want values in that sequence.

i want output

           echo  "var[0] var[1] var[2] " ;// it display value of $a1

or how create another array which copy values of array vaiables av . and sequence equal to array var

Update 1 :

update 1 :

AV array consist variables suppose 4. a = array ( "$a1" , "$a2" , "$a3", "$a4" ) . // actually i used loop for that its near 20 - 30 variables.

Now I assigned values to $a1 , $a2 , ... using for loop and POST method.

if i write

         echo  " a[0] " ;  // it display $a1

         echo " a1 = $a1"; // it display  actual value that i need eg. a1= 555

       $v = array ( "$a1" , "$a1" ,"$a1" , "$a1");

       now  i want To print array $v with value. 

      now $v[0] consist value $a1. 
      if i print $v[0] it display $a1. but i need value of $a1 i.e 555

       OR same $v array with actual variables values with same order 
infused
  • 24,000
  • 13
  • 68
  • 78
Mr. Bhosale
  • 3,018
  • 1
  • 17
  • 34

2 Answers2

0

I didnt rly understand what your actual problem is, but it seems like you want to merge 2 arrays together. Then you should take a look at array_merge()

http://php.net/manual/en/function.array-merge.php

$av = array(1, 2, 3, 4, 5);
$var = array("a", "b", "c", "d");
$output =  array_merge($av, $var);
print_r($output);

Output:

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => a
    [6] => b
    [7] => c
    [8] => d
)
Realitätsverlust
  • 3,941
  • 2
  • 22
  • 46
0

Did I read this right?

Don't forget your $ and your semicolons at the end.

   $av = array("Cow", "Chicken", "Hen", "Rooster");
    $var = array();
    foreach($av as $k=>$v){
    $var[$k] = $v;
    }
    echo  "$var[0] $var[1] $var[2] ";
I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116
  • `$var = $av` - what are you looping for? – deceze Jan 24 '14 at 06:24
  • The OP obviously doesn't know the solution, else he wouldn't be asking. Your code can simply be replaced with one `=`, and should be. Looping is absolutely pointless here. – deceze Jan 24 '14 at 06:30
  • very true, but he asked a question and i answered it the way he requested. what's the problem? – I wrestled a bear once. Jan 24 '14 at 06:32
  • Not Work .. Read Update 1 . array $var consist sequence variable $a1, $a1, $a1, $a2 . now how assing values to it which have already value like $a=555 – Mr. Bhosale Jan 24 '14 at 06:57