Archive

Posts Tagged ‘array’

PHP Session Array

Oct 21st, 2009

In beginning, programmer think whether they can store array or not in PHP session.
Yes, you can store array in php session.

More on Associative Array in Javascript

Jun 22nd, 2008

In this article about associative array, which looks similar to associative array in PHP. Here is some more ways for simulating associative array like things in Javascript:

<script type=”text/javascript”>

var obj = new Object();

obj['name'] = ’satya’;
obj['sex'] = ‘male’;
obj['city'] = ‘Patna’;
obj['age'] = ‘30′;

// this method is not working with Iterator.
obj.length = function () {
ln=0;
for (var [...]

Associative array in Javascript

Jun 14th, 2008

Javascript do not have associative array like PHP. In PHP you may have enjoyed associative array.
Here is something similar to associative array in JavaScript. But as it is not an associative array, so you cannot use JavaScript array methods. It is JSON style Object representation.

<script type=”text/javascript”>

var salesPerson = { “firstName”: “crockford”,
[...]

Search in Key/ Index of an Associative PHP Array

Mar 15th, 2008

Find the value in key of PHP array. I need to search in big array and that need to be fast. So, I was searching for fastest possible method. I was doing sorting also based on key and value on array. Array’s structure was fixed.

Check and Remove Duplicate Values from PHP Array

Jun 17th, 2007

PHP code for directly removing duplicate entry in Array and also test only script to check duplicate value in array

PHP array – Common Usage

Jun 17th, 2007

You will use “print_r” and “foreach” many times during programming at the time of using array.

<?php
$arr3 = array(‘a’, ‘b’, ‘c’, ‘d’);

echo ‘<pre>’;
print_r($arr2);
echo ‘</pre>’;
?>

print_r() will print whole array with key=>value pair in human readable format.
Delete every item, but not array

foreach ($arr3 as $key=>$value) {
unset($arr3[$key]);
}
foreach is specifically made for array. It provides an easy way to traverse [...]

Array in PHP

Jun 17th, 2007

Array Syntax:
array ([key=>] value,)
Key may be an integer or string, and value may be any value.
<?php

$arr1 = array (‘lang’=>’php’, 1=>true, 13);

echo $arr1['lang'] ; // print php
echo $arr1[1]; // 1
echo $arr1[2]; // 13
?>
As you can see above string ‘key’ is quoted.
An array [...]

Set/Get Cookie using PHP and JavaScript

May 15th, 2007

Cookie using JavaScript and also Cookie using PHP. Various ways of setting Cookie, example – set cookie through JavaScript and get through PHP.