Latest Post
Tampilkan postingan dengan label array. Tampilkan semua postingan
Tampilkan postingan dengan label array. Tampilkan semua postingan

Join us ...

Written By Unknown on Senin, 09 September 2013 | 22.24

How to convert a string into array in php ?

Written By Unknown on Kamis, 22 Agustus 2013 | 03.53

<?php
$str="Example";
$arr=array();
$arr=str_split($str);
echo "<pre>";
print_r($arr);
echo "</pre>";
?>

How to send an array in url in php ?

Written By Unknown on Rabu, 21 Agustus 2013 | 23.04

File.php  (This file contain array )

<?php

$data = array('foo'=>'bar',
              'baz'=>'boom',
              'cow'=>'milk',
              'php'=>'script');

$arr=http_build_query($data);

?>
<a href="nextpage.php?<?php echo $arr; ?>">Sendarray</a>


--------------------------------------------------------------------------------------------------------------------------------

nextpage.php (This file will receive array and print it)


<?php
echo "<pre>";
print_r($_GET);
echo "</pre>";
?>

How to preview array in Php ?

Written By Unknown on Selasa, 20 Agustus 2013 | 23.14

Array

<?php

$arr=array(1,2,3,4,5);
echo "<pre>";
print_r($arr);
echo "</pre>";

?>

Convert a Multidimensional Array Into Single Dimension using php

Written By Unknown on Jumat, 07 Mei 2010 | 00.51


I have wrapped three static functions for converting multidimensional configuration data. It is very much useful when working with configuration data. I have used this class in one of my project to store arbitrary configuration data just like windows registry data.

File: rayarray.php
<?php
/**Ray
Array arrays utility class
* *
*
This class provides configuration array handling funcionalities,

* may be usefull when dealing with configuration data. *
*
* Usage: using this class you can convert a multidimensio
nal configuration
array into a single dimension array ready to store into

sql table/ flat file. * * methods available are *  - shorten() - static *  - unshorten() - static *  - subarray() - static *
raynux.com * @website
* @package     raynux * @subpackage  raynux.lab.array * @version     1.0 * @author      Md. Rayhan Chowdhury * @email       ray
@     www.raynux.com * @license     GPL */ class RayArray{ /**
array concatenating all keys with separator. * * @example array('country' => array(0 => array('name' => '
* Shorten an multidimensional array into a single dimensional
Bangladesh', 'capital' => 'Dhaka'))) *          to array('country.0.name' => 'Bangladesh', 'country.0.capital' => 'Dhaka') *
@param string $separator, array key path separator * @return array, single dim
* @param array $inputArray, arrays to be marged into a single dimensional array * @param string $path, Default Initial path
*ensional array with key and value pair * @access public * @static */ static public function shorten(array $inputArray, $path = null, $separator = "."){ $data = array(); if (!is_null($path)) {
} else { $data =
$path = $path . $separator; } if (is_array($inputArray)) { foreach ($inputArray as $key => &$value) { if (!is_array($value)) { $data[$path . $key] = $value;
array_merge($data, self::shorten($value, $path . $key, $separator)); } } } return $data; } /** * Unshorten a single dimensional array into multidimensional array. *
aram array $data data to be converted into multidimensional array * @param string
* @example array('country.0.name' => 'Bangladesh', 'country.0.capital' => 'Dhaka') *          to array('country' => array(0 => array('name' => 'Bangladesh', 'capital' => 'Dhaka'))) * * @
p$separator key path separator * @return array multi dimensional array * @access public * @static */ static public function unshorten($data, $separator = '.'){ $result = array(); foreach ($data as $key => $value){ if(strpos($key, $separator) !== false ){
lue)?  self::unshorten($value, $separator) :
$str = explode($separator, $key, 2); $result[$str[0]][$str[1]] = $value; if(strpos($str[1], $separator)){ $result[$str[0]] = self::unshorten($result[$str[0]], $separator); } }else{ $result[$key] = is_array($v
a$value; } } return $result; } /** * Get part of array from a multidimensional array specified by concatenated keys path. * * @example *          path = "0.name" *          data = *          array( *                  array('name' => array('Bangladesh', 'Srilanka', 'India', 'Pakistan')),
' * @return mixed and return NULL if not found.
*                  array('help' => 'help.php'), *                  'test' => 'value', *                  10 => *          false) *          will return array('Bangladesh', 'Srilanka', 'India', 'Pakistan') * @param string $path * @param array $data * @param string $separator path separator default '
. * @access public * @static */ static public function subarray($path, &$data, $separator = '.') { if (strpos($path, $separator) === false) { if (isset($data[$path])) { return $data[$path]; } } else { $keys = explode($separator, $path, 2); if (array_key_exists($keys[0], $data)) {

return self::subarray($keys[1], $data[$keys[0]], $separator); } } } }

?>


Please drop me a line if you find this class useful or you have a different opinion.

Arrays in PHP

Written By Unknown on Kamis, 17 Desember 2009 | 09.05

Array is an single variable that holds multiple values. In an array you can store the related values into a single variable. 


If you have a list of items like (banana,apple,orange), then storing the fruits in a single variable could look like this:

$fruit1="banana";
$fruit2="apple";
$fruit3="orange";

 If you want to store 3 values is no problem. When it goes upto 100 or 200 then there may be a problem raised. The best solution to avoid this is to use an Array.

In PHP, there are three kinds of arrays. They are
            Numeric arrays - An array with numeric index
            Associative array - An array where each ID key is associated with a value.
            Multi dimensional array - An array containing one or more arrays.

Numeric arrays:
In PHP, there are 2 ways to create a numeric array

1. Index are automatically assigned. Example

   $fruits=array("banana","apple","orange");

2. Assign the indexes manually. Example
   $fruit[0]="banana";
   $fruit[1]="apple";
   $fruit[2]="orange";

Associative array:
In an associative array each ID key is associated with a value.
When storing data about specific named values, a numerical array is not always the best way to do it.
With associative arrays we can use the values as keys and assign values to them.

There are 2 ways to create an associative array
1.,
$age = array("Kennedy"=>32, "Lincoln"=>30, "Bush"=>34);

2.,ID keys are used in a script
$ages['Kennedy'] = "32";
$ages['Lincoln'] = "30";
$ages['Bush'] = "34";

echo "Kennedy is " . $ages['kennedy'] . " years old.";


OUTPUT:
Kennedy is 32 years old.




 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger