Skip to main content

Posts

Showing posts from June, 2016

Create multi dimension array

<?php //create 4*4 integer multidimensional array   $a=array(array(1,2,3,4),     array(1,2,3,4),     array(1,2,3,4),     array(1,2,3,4));       /*  create 4*4  multidimensional array containing   variable data type values */    $b=array(array(1,"JAVA",3,4.1),     array(1,"C++",3,4.2),     array(1,"PHP",3,4.3),     array(1,"PYTHON",3,4.4));       //print array   echo "Array a :<br><br>";   printMatrix($a);   echo "<br>Array b :<br><br>";   printMatrix($b);       //user defined function to print multidimensional array   function printMatrix($matrix)   {     for($i=0;$i<count($matrix);$i++)       {    ...

Continue in php

<?php $x=array("10","20","30","40","50"); foreach ($x as $value) {         if($value==30){        continue; // It causes for loop to jump on next iteration     }      echo $value . " "; } ?>

Check cookies in php

<?php       /*     setcookie(name, value, expire, path, domain, secure, httponly);     Only the name parameter is required.     All other parameters are optional.   */   setcookie("test_cookie", "test", time() + 3600, '/');     if(count($_COOKIE) > 0)   {       echo "Cookies are enabled.";   }   else   {       echo "Cookies are disabled.";   } ?>

Associative array in php

<?php   $language["C"]="nice"; $language["C++"]="very nice"; $language["JAVA"]="amazing"; $language["PYTHON"]="mind blowing";   echo "C is ".$language["C"]; echo ", C++ is " . $language["C++"]; echo ", JAVA is " . $language["JAVA"]; echo  " and PYTHON is ".$language["PYTHON"];   ?>