Pramod T P

Search
Skip to content
  • Home
  • PHP
  • WordPress
  • Linux
  • Magento
  • My SQL
  • Profile
  • comments

Daily Archives: May 11, 2011

PHP

Fetch an element from the array randomly – PHP

May 11, 2011 Pramod T P Leave a comment
<?php
 $testArray = array("value1", "value2", "value3", "value4");
 $testRand = array_rand($testArray, 2);
 echo $testArray[$testRand[0]];
?>
ArrayPHPString functions
PHP

Sort the element of an array in reverse order – PHP

May 11, 2011 Pramod T P Leave a comment
<?php
 $testArray = array("p", "c", "z", "a");
 rsort($testArray);
 print_r($testArray);
 //Array ( [0] => z [1] => p [2] => c [3] => a )
?>
ArrayPHPString functions
PHP

Sort the element in an array – PHP

May 11, 2011 Pramod T P Leave a comment
<?php
 $testArray = array("p", "c", "z", "a");
 sort($testArray);
 print_r($testArray);
 //Array ( [0] => a [1] => c [2] => p [3] => z )
?>
ArrayPHPString functions
PHP

Function to add an element into an array – PHP

May 11, 2011 Pramod T P 1 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

Posts navigation

1 2 3 Next →

Zend | Magento Certified PHP | eCommerce Architect

For Latest Updates
Visit phpcodez.com

Categories

Recent Posts

  • Regular expression
  • preg_match
  • Redirect root domain to a subdomain .htaccess
  • Redirect root domain to a subfolder .htaccess
  • Force SSL htaccess
May 2011
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
3031  
« Apr   Jun »

Recent Comments

togel online's avatartogel online on How to terminate the current s…
business funding's avatarbusiness funding on compare two strings – ja…
unsecured loans uk's avatarunsecured loans uk on Function to add an element int…
treating back pain's avatartreating back pain on Submit HTML form to pop up pag…
Pura Cleanse's avatarPura Cleanse on Add the block "Based on y…
  • RSS - Posts
Blog at WordPress.com.
Pramod T P
Create a free website or blog at WordPress.com.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Subscribe Subscribed
    • Pramod T P
    • Already have a WordPress.com account? Log in now.
    • Pramod T P
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
 

Loading Comments...