0

I have problem with my code here, I want convert serialize data in wordpress like this

$data ='a:2:{i:0;a:8:{s:8:"order_id";s:2:"19";s:5:"print";s:18:"type-canvas-framed";s:4:"size";s:12:"08-x-10-inch";s:18:"frame_canvas_color";s:10:"blackframe";s:11:"orientation";s:8:"portrait";s:3:"qty";s:1:"1";s:5:"price";d:42.990000000000002;s:8:"shipping";d:13.800000000000001;}i:1;a:7:{s:8:"order_id";s:2:"19";s:5:"print";s:11:"type-poster";s:4:"size";s:12:"36-x-48-inch";s:11:"orientation";s:8:"portrait";s:3:"qty";s:1:"1";s:5:"price";d:42.990000000000002;s:8:"shipping";d:14.800000000000001;}}' ;

I do parse the data using unseriliaze using unserialize the result like this

$result=array (
  0 => 
  array (
    'order_id' => '19',
    'print' => 'type-canvas-framed',
    'size' => '08-x-10-inch',
    'frame_canvas_color' => 'blackframe',
    'orientation' => 'portrait',
    'qty' => '1',
    'price' => 42.99,
    'shipping' => 13.8,
  ),
  1 => 
  array (
    'order_id' => '19',
    'print' => 'type-poster',
    'size' => '36-x-48-inch',
    'orientation' => 'portrait',
    'qty' => '1',
    'price' => 42.99,
    'shipping' => 14.8,
  ),
);

I want to looping the array, how to do that in wordpress.

Thanks

1
  • Did looking up "Looping Array" not work? You may want to research more thoroughly. Commented Jun 27, 2015 at 13:15

2 Answers 2

1

you dont need wordpress specific functions for that use:

foreach($result as $key => $value){
    // process array
}
Sign up to request clarification or add additional context in comments.

Comments

1

just use foreach

foreach($result as $key => $value ) {
    echo $value['order_id'];
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.