How to add template in codeigniter |how to create template in codeigniter| template in codeigniter 4
PHP ARRAY
Array is a data structure where we can collect multiple data in a variable. Array stores and collects data using index.
In this tutorial I will show you how to store array value in a variable and print array value in PHP programming language. In PHP Array can store many many value in a single variable and display in storing value in php.
PHP array two types – 1) Index Array 2) Associative Array.
syntax :
$val = array(data with , (comma) separation);
Example of Indexed Array
<?php $arr = array(5,43,78,22); // This array stores four values echo $arr[0].'<br>'; //array index start from zero(0), so output will be 5 echo $arr[1].'<br>'; //second index value will be 43 echo $arr[2].'<br>'; //third index value will be 78 and so on. print_r($arr); // It print all array values. var_dump($arr); // it print all array values with data type. ?>
show array value using foreach loop
<?php $arr = array(4,5,6,7); foreach($arr as $val) { echo $val.'&lt;br&gt;'; } ?>
Associative Array :
Index array start indexing from 0 to n-1. But in associative array indexing will be a text except a number. for example
<?php $arr =array ('a'=>'Apple','b'=>'Ball','c'=>'Cat'); //here a, b ,c is index of array and Apple,Ball, Cat are value of that index respectively. echo $arr['a'].'<br>'; echo $arr['c'].'<br>'; ?>
PHP array has many function you can get them in PHP Manual
Related posts