Json code Array 2 Array (ZF2)

Controller :

$arrYear = array(“1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “10”, “11”, “12”);
$arrNameYear = array(“Jan”, “Feb”, “Mar”, “Apr”, “May”, “Jun”, “Jul”, “Aug”, “Sep”, “Oct”, “Nov”, “Dec”);

$temp = array();
foreach($arrNameYear as $n => $name):

foreach($arrYear as $y => $year):

$temp[$y] = [$arrNameYear[$y].””,””.$arrYear[$y]];

endforeach;

endforeach;

View : (phtml)

<?php echo json_encode($temp);?>

Output :

[[“Jan”,”1″],[“Feb”,”2″],[“Mar”,”3″],[“Apr”,”4″],[“May”,”5″],[“Jun”,”6″],[“Jul”,”7″],[“Aug”,”8″],[“Sep”,”9″],[“Oct”,”10″],[“Nov”,”11″],[“Dec”,”12″]]

Credit by : www.iDevelopper.net

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s