Skip to content

PHPCodez

Search
  • PHP
  • Magento
  • Javascript
  • HTML
  • My SQL
  • Functions
  • WordPress
  • Plugins
  • Joomla
  • Linux
  • jQuery
  • Profile
  • comments
PHP

Function to add an element into an array – PHP

May 11, 2011 Pramod T P Leave a comment
<?php
 $testArray = array("value1", "value2");
 array_push($testArray, "value3", "value4");
 print_r($testArray);
 //rray ( [0] => value1 [1] => value2 [2] => value3 [3] => value4 )
?>
ArrayPHPString functions
PHP

Search an element in an array and return the key – PHP

May 11, 2011 Pramod T P Leave a comment
<?php
 $testArray = array(0 => 'value1', 1 => 'value4', 2 => 'value2', 3 => 'value3');
 $key = array_search('value2', $testArray); // $key = 2;
 echo "Key is ".$key ; // 2
?>
ArrayPHPString functions
PHP

Find out the product of elements in an array – PHP

May 11, 2011 Pramod T P Leave a comment
<?php
 $testArray = array(3, 2, 4, 7);
 echo "product is " . array_product($testArray);
 // product is 168
?>
ArrayPHPString functions
PHP

Function to replace array elements – PHP

May 11, 2011 Pramod T P Leave a comment
<?php
 $testArray = array("orange", "banana", "apple", "raspberry");
 $replaceArr1 = array(0 => "pineapple", 3 => "cherry");
 $replaceArr2 = array(0 => "grape");
 $basket = array_replace($testArray, $replaceArr1, $replaceArr2);
 print_r($basket);
 //Array ( [0] => grape [1] => banana [2] => apple [3] => cherry )
?>
ArrayPHPString functions
PHP

Find out the difference of arrays – PHP

May 11, 2011 Pramod T P Leave a comment
<?php
 $testArray1 = array("key1" => "val1", "key2" => "val2", "val4");
 $testArray2 = array("key4" => "val3", "val2", "val7");
 $testArray3 = array_diff($testArray1, $testArray2);
 print_r($testArray3);// Array ( [key1] => val1 [0] => val4 )
?>
ArrayPHPString functions
PHP

Function to fill an array with specified values – PHP

May 11, 2011 Pramod T P Leave a comment
<?php
 $testArray = array_fill(5, 3, 'Value1');
 print_r($testArray);
 //Array ( [5] => Value1 [6] => Value1 [7] => Value1 )
?>
ArrayPHPString functions
PHP

Pad values to an array with specified length – PHP

May 11, 2011 Pramod T P Leave a comment
<?php
 $testArray = array(12, 10, 9);
 print_r( array_pad($testArray, 6, 0));
 //  Array ( [0] => 12 [1] => 10 [2] => 9 [3] => 0 [4] => 0 [5] => 0 )
?>
ArrayPHPString functions
PHP

Fetch previous element of an array – PHP

May 11, 2011 Pramod T P Leave a comment
<?php
 $testArray = array('foot', 'bike', 'car', 'plane');
 next($testArray);  next($testArray);
 echo prev($testArray); // bike
?>
ArrayPHPString functions
PHP

Fetch current element of an array – PHP

May 11, 2011 Pramod T P Leave a comment
<?php
 $testArray = array('foot', 'bike', 'car', 'plane');
 echo current($testArray);    // foot
?>
ArrayPHPString functions
PHP

Find out the next element of an array – PHP

May 11, 2011 Pramod T P Leave a comment
<?php
 $testArray = array('foot', 'bike', 'car', 'plane');
 secho next($testArray);    // bike
?>
ArrayPHPString functions

Posts navigation

← Previous 1 … 93 94 95 … 101 Next →

Beginners' Guide

Recent Posts

  • Upstream sent too big header while reading response
  • Navigate to a Folder from Any Location by Typing a Letter – Linux
  • Magento 2 Admin Content Deployment
  • React vs next JS
  • Disable CAPTCHA Magento 2 Admin Login
  • Difference Between composer.json and composer.lock Files
  • Magento 2 Regenerate URL Rewrites Manually For Categories
  • Magento 2 Regenerate URL Rewrites Manually for Products
  • composer self downgrade

Recent Comments

  • sunny on cgi.force_redirect
  • beats solo 4 on allow_url_include
  • Hairstyles on php end of line
  • penipu on cgi.force_redirect
  • lumi777 link alternatif on cgi.force_redirect

Categories

  • .htaccess (32)
  • Ajax (4)
  • Apache (43)
  • AWS (11)
  • Cookie (4)
  • Database Model (9)
  • Design Pattern (9)
  • Filter (27)
  • General (187)
  • HTML (5)
  • IP.Board (1)
  • Javascript (99)
  • Jetty (3)
  • Joomla (17)
  • jQuery (63)
  • JSON (3)
  • JSP (1)
  • Linux (125)
  • Magento (371)
  • My SQL (74)
  • nginx (4)
  • OOPs (12)
  • Payment Gateway (1)
  • PHP (1,005)
  • Plugins (11)
  • Prototype (1)
  • session (5)
  • Socialengine (1)
  • SQL (69)
  • SVN (17)
  • Uncategorized (11)
  • Vbulletin (11)
  • Wordpress (89)
Proudly powered by WordPress