How to generate an array in PHP then JSON encode?

In this tutorial learn generate an array in php from value and then convert array to JSON encode format, convert an array in php first to store value in array and then convert into JSON encode using jsonencode() funcition

<?php
$AR = array();
for($i=1;$i<5;$i++) { 
  $AR[] = array('date' => date("d m Y",strtotime("+".$i." days")), 'id' => $i);
}
echo json_encode($AR);?>

OUTPUT :


[
  • {
    • date"05 05 2019",
    • id1
    },
  • {
    • date"06 05 2019",
    • id2
    },
  • {
    • date"07 05 2019",
    • id3
    },
  • {
    • date"08 05 2019",
    • id4
    }
]

1 comment:

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...