array (size=10)
  'item-_token' => string 'k4i2tQbZNuKnhV0vqbdBJ0XlwKzGLm09KA0pWa5n' (length=40)
  'item-link' => 
    array (size=3)
      0 => string 'link 1' (length=6)
      1 => string 'link 2' (length=6)
      2 => string 'link 3' (length=6)
  'item-shop_name' => 
    array (size=3)
      0 => string 'a' (length=1)
      1 => string 'b' (length=1)
      2 => string 'c' (length=1)
  'item-color' => 
    array (size=3)
      0 => string 'blue' (length=4)
      1 => string 'yellow' (length=6)
      2 => string 'black' (length=5)
  'item-note' => 
    array (size=3)
      0 => string 'Nho' (length=3)
      1 => string 'em' (length=2)
      2 => string 'nhieu' (length=5)
  'item-size' => 
    array (size=3)
      0 => string 'z' (length=1)
      1 => string 's' (length=1)
      2 => string 's' (length=1)
  'item-quantity' => 
    array (size=3)
      0 => string '13' (length=2)
      1 => string '12' (length=2)
      2 => string '12' (length=2)
  'item-price' => 
    array (size=3)
      0 => string '15' (length=2)
      1 => string ' 53' (length=3)
      2 => string '56' (length=2)
  'item-amount' => 
    array (size=3)
      0 => string '33' (length=2)
      1 => string '323' (length=3)
      2 => string '323' (length=3)
  'item-ship' => 
    array (size=3)
      0 => string '22' (length=2)
      1 => string '22' (length=2)
      2 => string '44' (length=2)

I have a array on. Now I want meger array to object same:
array('item-link-0' => 'link 1', 'item-shop_name-0' => 'a', 'item-color-0' => 'blue', 'item-size-0' => 'z',.....)
array('item-link-1' => 'link 2', 'item-shop_name-1' => 'a', 'item-color-1' => 'blue', 'item-size-1' => 'z',.....)
......

Something like this might help:

$oldArray = array(
    'item-_token' => 'k4i2tQbZNuKnhV0vqbdBJ0XlwKzGLm09KA0pWa5n',
    'item-link' => array ('link 1', 'link 2', 'link 3'),
    'item-shop_name' => array('a', 'b', 'c'),
    'item-color' => array('blue', 'yellow', 'black')
    // ...
);

$newArray = array();

foreach($oldArray as $key1 => $arr1) {
    // do not know what to do with the item-_token element so skipped it
    if($key1 == 'item-_token') {
        continue;
    }
    foreach($arr1 as $key2 => $val2) {
        $newKey2 = $key1 . '-' . $key2;
        $newArray[$key2][$newKey2] = $val2;
    }
}

echo '<pre>';
echo print_r($oldArray, 1);
echo print_r($newArray, 1);
echo '</pre>';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.