<?php
$a = array(array());
$k = 0;
for($i=0;$i<5;$i++){
for($j=0;$j<3;$j++){
$a[$i][$j] = $k++ % 10;
}
}
for($i=0;$i<5;$i++){
for($j=0;$j<3;$j++){
echo $a[$i][$j];
}
}
?>
Saturday, March 16, 2013
Two Dimentional array in PHP
Monday, December 31, 2012
Array in PHP
<?php
//decleartion of an array
$num = array(1,2,4,6,3);
//printing the array elements
foreach($num as $ar){
echo $ar.'<br>';
}
?>
Create a simple addition function in PHP
<?php
//decleartion of a function
function addition($x,$y){
$res = $x + $y;
return $res;
}
$x = 4; //initializing the variable x
$y = 7; //initializing the variable y;
$res = addition($x,$y); //holding the result
echo 'The addtion of x and y is: '.$res; //printing the addition result;
?>
Giving condition in PHP
<?php
$x = 5;
$y = 9;
if($x > $y) echo 'x is greater than y';
else echo 'x is less than y';
?>
While Loop in PHP
<?php
$var = 'I love PHP'; //initialize the string variable var
$i=0; // initialize i = 0
while($i<5){
echo $var.'<br>'; //printing 5 times the string var
$i++; //incrementing the value of i
}
?>
For Loop in PHP
<?php
$var = 'I love PHP';
for($i=0; $i<5; $i++){
echo $var.'<br>'; //printing 5 times the string var;
}
?>
Finding the Length of a string in PHP
<?php
$x = 'Mohammad Rakibul Haider'; //variable x holds my name
echo strlen($x); //printing my name's length
?>
Subscribe to:
Comments (Atom)