fork download
  1. <?php
  2.  
  3. $data = array
  4. (
  5. 'USD',
  6. '10150.00',
  7. '9850.00',
  8. 'SGD',
  9. '8015.40',
  10. '7915.40',
  11. 'HKD',
  12. '1304.60',
  13. '1288.60',
  14. );
  15.  
  16. $result = array();
  17.  
  18. while (is_null($value = array_shift($data)) !== true)
  19. {
  20. if (preg_match('~^[A-Z]{3}$~', $value) > 0)
  21. {
  22. $result[$value] = array
  23. (
  24. 'Buy' => array_shift($data),
  25. 'Sell' => array_shift($data),
  26. );
  27. }
  28. }
  29.  
  30. print_r($result); // transformed array
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Array
(
    [USD] => Array
        (
            [Buy] => 10150.00
            [Sell] => 9850.00
        )

    [SGD] => Array
        (
            [Buy] => 8015.40
            [Sell] => 7915.40
        )

    [HKD] => Array
        (
            [Buy] => 1304.60
            [Sell] => 1288.60
        )

)