Posts

Showing posts from October, 2023

Object Instance Working with Strings

  Classes are nothing without objects.We can create multiple objects from a class. Each object has all the properties and methods defined in the class, but they will have different property values. An object of a class is created using the new keyword. Example: $bsc and $bzc is instances of the class Group: <?php class Group { public $name; function set_name($name) {     $this->name=$name; } function get_name; {     return $this->name; } } $bsc=new Group(); $bzc=new Group(); $bsc->set_name('BSC'); $bzc->set_name('BZC'); echo $bsc->get_name(; echo "<br>"; echo $bzc->get_name(); ?>

Objects in PHP

  Define Objects Classes are nothing without objects! We can create multiple objects from a class. Each object has all the properties and methods defined in the class, but they will have different property values. Objects of a class are created using the  new  keyword. In the example below, $apple and $banana are instances of the class Fruit: Syntax To declare an object of a class we need to use new statement class myclass {    ..    .. } $obj=new myclass; Example <?php class  Fruit {    // Properties    public  $name;    public  $color;    // Methods    function  set_name($name) {     $this->name = $name;   }    function  get_name() {      return  $this->name;   } } $apple =  new  Fruit(); $banana =  new  Fruit(); $apple->set_name( 'Apple' ); $banan...

PHP Array Functions

  PHP  Array  Functions The array functions allow you to access and manipulate arrays. Simple and multi-dimensional arrays are supported. Function Description array() Creates an array array_column() Returns the values from a single column in the input array array_combine() Creates an array by using the elements from one "keys" array and one "values" array array_flip() Flips/Exchanges all keys with their associated values in an array array_pop() Deletes the last element of an array array_push() Inserts one or more elements to the end of an array array_replace() Replaces the values of the first array with the values from following arrays array_reverse() Returns an array in the reverse order array_search() Searches an array for a given value ...

PHP Arrays

  PHP Arrays PHP array is an ordered map (contains value on the basis of key). It is used to hold multiple values of similar type in a single variable. Advantage of PHP Array Less Code : We don't need to define multiple variables. Easy to traverse : By the help of single loop, we can traverse all the elements of an array. Sorting : We can sort the elements of array. PHP Array Types There are 3 types of array in PHP. Indexed Array Associative Array Multidimensional Array PHP Indexed Array PHP index is represented by number which starts from 0. We can store number, string and object in the PHP array. All PHP array elements are assigned to an index number by default. There are two ways to define indexed array: 1st way: 1.        $season = array ( "summer" , "winter" , "spring" , "autumn" );   2nd way: 1.        $season [0]= "summer" ;   2. ...