PHP Notes and Examples: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
| Line 19: | Line 19: | ||
</pre> | </pre> | ||
Example Try Catch block | |||
<pre> | |||
Use Exception; | |||
try { | |||
someRandoFunction; | |||
} | |||
catch (Exception $e) { | |||
doSomethingWhenErrorFound; | |||
} | |||
catch (ErrorName $e) { | |||
cryToMamma; | |||
} | |||
</pre> | |||
====Slim4 Framework Notes==== | ====Slim4 Framework Notes==== | ||
Revision as of 13:52, 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[??};
}
Example Try Catch block
Use Exception;
try {
someRandoFunction;
}
catch (Exception $e) {
doSomethingWhenErrorFound;
}
catch (ErrorName $e) {
cryToMamma;
}
Slim4 Framework Notes
return $this->respondWithData($data); throw new HttpBadRequestException($this->request, "Error message details");