[ create a new paste ] login | about

Link: http://codepad.org/AmVp08QR    [ raw code | output | fork ]

PHP, pasted on May 22:
1
2
3
4
5
6
7
8
9
10
11
12
13
<?
    $values = explode(",", "id,1,name,Test,city,chicago,username,testuser,contact_id,21,phone,123456789");

    $i = 0;
    $count = count($values);
    $object = array();

    for( ; $i < $count; $i++ ) {
        $object[$values[$i]] = $values[$i+1];
    }

    var_dump($object);
?>


Output:
array(12) {
  ["id"]=>
  string(1) "1"
  [1]=>
  string(4) "name"
  ["name"]=>
  string(4) "Test"
  ["Test"]=>
  string(4) "city"
  ["city"]=>
  string(7) "chicago"
  ["chicago"]=>
  string(8) "username"
  ["username"]=>
  string(8) "testuser"
  ["testuser"]=>
  string(10) "contact_id"
  ["contact_id"]=>
  string(2) "21"
  [21]=>
  string(5) "phone"
  ["phone"]=>
  string(9) "123456789"
  [123456789]=>
  NULL
}


Create a new paste based on this one


Comments: