Loading...
More PHP Posts
<?php$json ='{"id":1,"name":"foo","interest":["wordpress","php"]}';$obj=json_decode($json);echo $obj->interest[1]; //prints php?>
<?phpfunction getRandomId($min = NULL, $max = NULL) {if (is_numeric($min) && is_numeric($max)) {return mt_rand($min, $max);}else {return mt_rand();}}?>
<?php/** @param string $file Filepath* @param string $query Needed information (0 = width, 1 = height, 2 = mime-type)* @return string Fileinfo*/function getImageinfo($file, $query) {if (!realpath($file)) {$file = $_SERVER["DOCUMENT_ROOT"] . $file;}$image = getimagesize($file);return $image[$query];}?>
<?php//generate 239 rgba colors for codecatch's 239 supported programming languages!//this was used to generate the colors that are used in the pie chart on https://codecatch.net/graphs.phpfunction rgbagenerator() {$count = 239;for ($i=0; $i < $count; $i++) {echo "'rgba(". mt_rand(0,255) . ",". mt_rand(0,255) . ",". mt_rand(0,255) . ",1)',";echo "<br>";}}rgbagenerator();?>
<?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);}?>
<?phpheader('Content-Type:text/html');$jsonData = json_decode(file_get_contents("names.json"));$namesArray = array();foreach($jsonData as $data) {$namesArray[] = $data;}for($i = 0; $i < 64000; $i++) {echo 'D.add_edge("'. $namesArray[array_rand($namesArray)] . '", "' . $namesArray[array_rand($namesArray)]. '")';echo "<br>";}?>