PHP Notes and Examples: Difference between revisions

From I Will Fear No Evil
Jump to navigation Jump to search
(Created page with "===PHP Notes and Examples=== change Array to JSON <pre> $foo=json_encode($array,1); echo $foo . "\n"; </pre> Convert a VALID JSON string to array <pre> $foo=json_decode($json, True); print_r($foo); </pre> Example foreach loop (simple) <pre> foreach ($nestedArray1 as $Array1) { do something with new array $array1[??}; } </pre> Category:PHP")
 
mNo edit summary
Line 20: Line 20:




Slim4 Framework Notes
<pre>
return $this->respondWithData($data);
throw new HttpBadRequestException($this->request, "Error message details");
</pre>
[[Category:PHP]]
[[Category:PHP]]

Revision as of 14:50, 17 May 2023

PHP Notes and Examples

change Array to JSON

$foo=json_encode($array,1);
echo $foo . "\n";

Convert a VALID JSON string to array

$foo=json_decode($json, True);
print_r($foo);

Example foreach loop (simple)

foreach ($nestedArray1 as $Array1) {
  do something with new array $array1[??};
}


Slim4 Framework Notes

return $this->respondWithData($data);
throw new HttpBadRequestException($this->request, "Error message details");