• Nov 19, 2022 •CodeCatch
0 likes • 0 views
<?php $json ='{"id":1,"name":"foo","interest":["wordpress","php"]}'; $obj=json_decode($json); echo $obj->interest[1]; //prints php ?>
• Nov 18, 2022 •AustinLeath
0 likes • 1 view
<?php $array = array( 'fruit1' => 'apple', 'fruit2' => 'orange', 'fruit3' => 'grape', 'fruit4' => 'apple', 'fruit5' => 'apple'); // this cycle echoes all associative array // key where value equals "apple" while ($fruit_name = current($array)) { if ($fruit_name == 'apple') { echo key($array), "\n"; } next($array); } ?>
<?php function getRandomId($min = NULL, $max = NULL) { if (is_numeric($min) && is_numeric($max)) { return mt_rand($min, $max); } else { return mt_rand(); } } ?>
<?php $listOfFiles = glob("*.{jpg,png,gif,tiff,jpeg}", GLOB_BRACE); echo 'images = []; '; for($x = 0; $x <= count($listOfFiles)-1; $x++) { echo "images[" . $x . "] =" . '"' . $listOfFiles[$x] . '"' . "; "; } ?>
0 likes • 2 views
<?php function getFileExtension($file) { return end(explode(".", $file)); } ?>
<?php $im = imagecreatefrompng('example.png'); $size = min(imagesx($im), imagesy($im)); $im2 = imagecrop($im, ['x' => 0, 'y' => 0, 'width' => $size, 'height' => $size]); if ($im2 !== FALSE) { imagepng($im2, 'example-cropped.png'); imagedestroy($im2); } imagedestroy($im); ?>