 |
V. Array 数组函数
本类函数允许用多种方法来操作数组和与之交互。数组的本质是储存,管理和操作一组变量。
PHP 支持一维和多维数组,可以是用户创建或由另一个函数创建。有一些特定的数据库处理函数可以从数据库查询中生成数组,还有一些函数返回数组。
参见手册中的数组一节关于
PHP 是怎样实现和使用数组的详细解释。参见数组运算符一节关于怎样操作数组的其它方法。
本函数库作为 PHP 内核的一部分,不用安装就能使用。 本扩展模块在 php.ini 中未定义任何配置选项。 以下常量作为 PHP 核心的一部分一直有效。
排序顺序标识:
排序类型标识:用于各种排序函数
- SORT_REGULAR
(integer)
SORT_REGULAR 用于对对象进行通常比较。
- SORT_NUMERIC
(integer)
SORT_NUMERIC 用于对对象进行数值比较。
- SORT_STRING
(integer)
SORT_STRING 用于对对象进行字符串比较。
- SORT_LOCALE_STRING
(integer)
SORT_LOCALE_STRING 基于当前区域来对对象进行字符串比较。PHP
4.4.0 和 5.0.2 新加。
vinaur at gmail dot com
07-Jun-2006 04:36
Regarding the array to string (parse_line) and string to array (parse_array) functions posted below by Kevin Law.
The functions will not work correctly if the array being parsed contains values that include commas and possibly parentheses.
To solve this problem I added urlencode and urldecode functions and the result looks like this:
<?php
function parse_line($array){
$line = "";
foreach($array AS $key => $value){
if(is_array($value)){
$value = "(". parse_line($value) . ")";
}
else
{
$value = urlencode($value);
}
$line = $line . "," . urlencode($key) . ":" . $value . "";
}
$line = substr($line, 1);
return $line;
}
function parse_array($line){
$q_pos = strpos($line, ":");
$name = urldecode(substr($line,0,$q_pos));
$line = trim(substr($line,$q_pos+1));
$open_backet_pos = strpos($line, "(");
if($open_backet_pos===false || $open_backet_pos>0){
$comma_pos = strpos($line, ",");
if($comma_pos===false){
$result[$name] = urldecode($line);
$line = "";
}else{
$result[$name] = urldecode(substr($line,0,$comma_pos));
$result = array_merge($result, parse_array(substr($line,$comma_pos+1)));
$line = "";
}
}else if ($open_backet_pos==0){
$line = substr($line,1);
$num_backet = 1;
$line_char_array = str_split($line);
for($index = 0; count($line_char_array); $index++){
if($line_char_array[$index] == '('){
$num_backet++;
}else if ($line_char_array[$index] == ')'){
$num_backet--;
}
if($num_backet == 0){
break;
}
}
$sub_line = substr($line,0,$index);
$result[$name] = parse_array($sub_line);
$line = substr($line,$index+2);
}
if(strlen($line)!=0){
$result = array_merge($result, parse_array($line));
}
return $result;
}
?>
php_spam at erif dot org
28-May-2006 03:15
Public domain, yadda yadda. This is an extension of the assocSort below, patched up a bit. Feedback would be wonderful.
<?php
function assocMultiSort(&$array,$keys,$directions=true) {
if (!is_array($array) || count($array) == 0) return true;
if (!is_array($keys)) { $keys = Array($keys); }
//we want "current" instead of necessarily the "zeroth" element; there may not be a zeroth element
$test = current($array);
$assocSortCompare = '';
for ($i=0,$count=count($keys);$i<$count;$i++) {
$key = $keys[$i];
if (is_array($directions)) {
$direction = $directions[$i];
} else {
$direction = $directions;
}
if ($i > 0) $assocSortCompare .= 'if ($retval != 0) return $retval; ';
$assocSortCompare .= '$ax = $a["'.$key.'"]; $bx = $b["'.$key.'"];';
//TODO -- if it's "blank", search up the list until we find something not blank
if (is_numeric($test[$key]) || ($test[$key] == ((int)$test[$key]))) {
if ($direction) {
$assocSortCompare.= ' $retval = ($ax == $bx) ? 0 : (($ax < $bx) ? -1 : 1);';
} else {
$assocSortCompare.= ' $retval = ($ax == $bx) ? 0 : (($ax < $bx) ? 1 : -1);';
}
} else {
if ($direction) {
$assocSortCompare.= ' $retval = strcmp($ax,$bx);';
} else {
$assocSortCompare.= ' $retval = strcmp($bx,$ax);';
}
}
}
$assocSortCompare.= ' return $retval;';
$assocSortCompare = create_function('$a,$b',$assocSortCompare);
$retval = usort($array,$assocSortCompare);
return $retval;
}
?>
ben
14-Apr-2006 05:59
In reference to the cleanArray function below, note that it checks the value using the empty() function and removes it. This will also remove the integer value 0 and the string "0" among other possibly unexpected things. Check the manual entry for empty().
g dot bell at NOSPAM dot managesys dot com dot au
03-Apr-2006 06:57
/*
function to give array of ranks. Handles ties.
input $arr is zero based array to be ranked
$order is the sorting order
'asc' (default) ranks smallest as 1
'desc' ranks largest as 1
output zero based array of ranks.
Ties (repeated values) given equal (integer) values
*/
function array_rank($arr,$order='asc') {
// $direction parameter
foreach($arr as $being_ranked) {
$t1 = $t2 = 0;
if ($order == 'asc') {
foreach ($arr as $checking) {
if ($checking > $being_ranked) continue;
if ($checking < $being_ranked) {
$t1++;
} else {
$t2++; // equal so increment tie counter
}
}
} elseif ($order == 'desc') {
foreach ($arr as $checking) {
if ($checking < $being_ranked) continue;
if ($checking > $being_ranked) {
$t1++;
} else {
$t2++; // equal so increment tie counter
}
}
}
$ranks[] = floor($t1 + ($t2 + 1) / 2);
}
return $ranks;
}
administrador(ensaimada)sphoera(punt)com
31-Mar-2006 08:37
With this simple function you can convert a (partial) bidimensional array into a XHTML table structure:
<?php
$table = array();
$table[1][1] = "first";
$table[2][1] = "second";
$table[5][3] = "odd one";
$table[1][2] = "third";
echo matrix2table($table);
function matrix2table($arr,$tbattrs = "width='100%' border='1'", $clattrs="align='center'"){
$maxX = $maxY = 1;
for ($x=0;$x<100;$x++){
for ($y=0;$y<100;$y++){
if ($arr[$x][$y]!=""){
if ($maxX < $x) $maxX = $x;
if ($maxY < $y) $maxY = $y;
}
}
}
$retval = "<table $tbattrs>\n";
for ($x=1;$x<=$maxX;$x++){
$retval.=" <tr>\n";
for ($y=1;$y<=$maxY;$y++){
$retval.= (isset($arr[$x][$y]))
?" <td $clattrs>".$arr[$x][$y]."</td>\n"
:" <td $clattrs> </td>\n";
}
$retval.=" </tr>\n";
}
return $retval."</table>\n";
}
?>
more scripts at http://www.sphoera.com
elkabong at samsalisbury dot co dot uk
25-Mar-2006 06:31
Hello all! I've just been working on a system to automatically manage virtualhosts on an Apache box and I needed to duplicate some multidimensional arrays containing references to other multidimensional array some of which also contained references. These big arrays are defaults which need to be overwritten on a per-virtualhost basis, so copying references into the virtualhost arrays was not an option (as the defults would get corrupted).
After hours of banging me head on the wall, this is what I've come up with:
<?PHP # Tested on PHP Version 5.0.4
# Recursively set $copy[$x] to the actual values of $array[$x]
function array_deep_copy (&$array, &$copy) {
if(!is_array($copy)) $copy = array();
foreach($array as $k => $v) {
if(is_array($v)) {
array_deep_copy($v,$copy[$k]);
} else {
$copy[$k] = $v;
}
}
}
# To call it do this:
$my_lovely_reference_free_array = array();
array_deep_copy($my_array_full_of_references, $my_lovely_reference_free_array);
# Now you can modify all of $my_lovely_reference_free_array without
# worrying about $my_array_full_of_references!
?>
NOTE: Don't use this on self-referencing arrays! I haven't tried it yet but I'm guessing an infinate loop will occur...
I hope someone finds this useful, I'm only a beginner so if there's any fatal flaws or improvements please let me know!
alessandronunes at gmail dot com
19-Mar-2006 06:06
The Ninmja sugestion plus multidiomensional array search (recursive):
function cleanArray($array) {
foreach ($array as $index => $value) {
if(is_array($array[$index])) $array[$index] = cleanArray($array[$index]);
if (empty($value)) unset($array[$index]);
}
return $array;
}
padraig at NOSPAM dot ohannelly dot com
15-Mar-2006 01:08
Re removing blank elements from arrays, this is even more concise:
<?php
$arraytest = array_diff($arraytest, array(""));
?>
Nimja
23-Feb-2006 11:35
A very clean and efficient function to remove empty values from an Array.
<?php
function cleanArray($array) {
foreach ($array as $index => $value) {
if (empty($value)) unset($array[$index]);
}
return $array;
}
?>
eddypearson at gmail dot com
06-Feb-2006 04:40
Little function to remove blank values from an array (will not reorder indexes however):
function CleanA($arr) {
while ($count < count($arr)) {
if ($arr[$count] == "") {
unset($arr[$count]);
}
$count++;
}
return $arr;
}
Sebastian
01-Feb-2006 06:58
xxellisxx at gmail dot com:
see implode(), it does exactly what you want, but quicker.
$array = array();
$string = implode( '', $array );
xxellisxx at gmail dot com
20-Jan-2006 01:03
Super simple way of converting an array to a string.
function array_to_string($array)
{
foreach ($array as $index => $val)
{
$val2 .=$val;
}
return $val2;
}
spam at madhermit dot net
10-Jan-2006 09:26
Here is a function that recursively flattens an multidimensional array while maintaining keys. Hopefully it is useful to someone..
Example Input:
Array
(
[name] => John Doe
[email] => johndoe@earthlink.net
[addresses] => Array
(
[1] => Array
(
[address] => 555 Somewhere
[city] => Podunk
[state] => CA
[zip] => 90120
)
[2] => Array
(
[address] => 333 Someother Place
[city] => Podunk
[state] => CA
[zip] => 91103
)
)
)
Example output:
Array
(
[name] => John Doe
[email] => johndoe@earthlink.net
[address1] => 555 Somewhere
[city1] => Podunk
[state1] => CA
[zip1] => 90120
[address2] => 333 Someother Place
[city2] => Podunk
[state2] => CA
[zip2] => 91103
)
<?
function flattenArray($array,$keyname='')
{
$tmp = array();
foreach($array as $key => $value)
{
if(is_array($value))
$tmp = array_merge($tmp,flattenArray($value,$key));
else
$tmp[$key.$keyname] = $value;
}
return $tmp;
}
?>
Atomo64
04-Jan-2006 09:14
Here's a simple way to convert an array to a string and vice-versa.
Note that it does NOT support string keys,
for more information take a look at what it does:
<?php
class OptionAsArray
{
function make_the_arr($value)
{
$newValue=array();
$vals=explode('&',$value);
foreach($vals as $v)
{
if($v{0}=='@')
$newValue[]=$this->make_the_arr(
urldecode(substr($v,1)));
else
$newValue[]=urldecode($v);
}
if(empty($newValue))
return false;
else
return $newValue;
}
function make_the_value($arr)
{
$newValue=array();
foreach($arr as $value)
{
if(is_array($value))
$newValue[]='@'.urlencode(
implode('&',$this->make_the_value($value)));
else
$newValue[]=urlencode($value);
}
if(empty($newValue))
return false;
else
return $newValue;
}
}
?>
ryan1_00 at hotmail dot com
02-Jan-2006 12:02
The following will take a query result and create a dynamic table for it. Using the Key() function to get the table headers and the current() function for the actual values.
$result = mysql_query($qry) or die ("<center> ERROR: ".mysql_error()."</center>");
$x = 0;
echo "<table border=\"1\" align=\"center\">";
while($row = mysql_fetch_assoc($result))
{
if ($x == 0) // so that table headers are only created on the first pass
{
$col = (count($row)); // counts number of elements in the array
$x=1;
echo "<tr>";
for ($y=0; $y<$col; $y++)
{
echo "<th>";
echo key($row); // gets the names of the fields
echo "</th>";
next($row);
}
echo "</tr>";
}
reset($row);
echo "<tr>";
for ($y=0; $y<$col; $y++)
{
echo "<td valign=\"top\" align=\"left\">";
echo current($row);
echo"</td>";
next($row);
}
echo "</tr>";
} // end of while loop
jonathan at sharpmedia dot net
05-Dec-2005 10:37
/**
* Flattens a multimentional array.
*
* Takes a multi-dimentional array as input and returns a flattened
* array as output. Implemented using a non-recursive algorithm.
* Example:
* <code>
* $in = array('John', 'Jim', array('Jane', 'Jasmine'), 'Jake');
* $out = array_flatten($in);
* // $out = array('John', 'Jim', 'Jane', 'Jasmine', 'Jake');
* </code>
*
* @author Jonathan Sharp <jonathan@sharpmedia.net>
* @var array
* @returns array
*/
function array_flatten($array)
{
while (($v = array_shift($array)) !== null) {
if (is_array($v)) {
$array = array_merge($v, $array);
} else {
$tmp[] = $v;
}
}
return $tmp;
}
madness AT l33t DOT it
25-Nov-2005 01:18
A little function I like to use instead of the classic one, it lets me choose a better format an is overall more versatile:
<?
function get_image_size($filename, &$imageinfo){
$rawdata=getimagesize($filename, $imageinfo);
$refineddata=$rawdata;
if ($rawdata){
$refineddata=$rawdata;
$refineddata['width']=$rawdata[0];
$refineddata['height']=$rawdata[1];
$refineddata['type']=$rawdata[2];
$refineddata['attribute']=" ".$rawdata[3];
$refineddata[4]=$rawdata['mime'];
}
return $refineddata;
}
?>
Notice I also added the extra space in the attribute field, becuase I usually use it like this:
<?
echo "<img src=\\"foo.jpg"".$imgdata[attribute]." alt=\\"foo" />";
?>
This way if the attribute happens to be a null or empty value the tag doesn't contain double spaces.
stalker at ruun dot de
20-Nov-2005 05:15
I had some problems while selecting sub-arrays from multi-dimensional arrays (like the SQL-WHERE clause), so i wrote the following function:
<?php
function selectMultiArray($__multiarray,$__key,$__value) {
foreach($__multiarray as $multipart) {
if($multipart[$__key] == $__value) {
$__return[] = $multipart;
}
}
if(empty($__return)) {
return FALSE;
}
return $__return;
}
?>
hope someones finding this helpful. If you have better was for getting to this, please answer.
greets,
St4Lk3R
Rajaratnam Thavakumar--thava16 at gmail dot com
25-Oct-2005 11:16
<?php
/*
This will return the N possible future dates acording to your selections of parameters
mydates_array([Which Week in a Month],[Which Day in a Week],[No of Dates have to return])
Eg:- Every 2nd Sunday mydates_array(2,0,10)
$Dateid---> Sunday - 0 , Monday - 1 , Tuesday - 2, Wednesday - 3,
Thursday - 4 , Friday - 5 , Saturday - 6
$weekid---> * can not be greater than 6
* if weekID is equal 6 it will return the Last Day of the weeek.
* Eg:-mydates_array(6,1,10);
* it will Returns 10 Last Mondays
* Please note weekid 5 is not availble in all months.mydates_array will not returns $no_returns that you want.
* Eg:-mydates_array(5,1,10);
* it will Returns 5th Monday
$no_returns--> No of dates that you want
By: Rajaratnam Thavakumar(thava16@hotmail.com)
*/
function mydates_array($weekid,$Dateid,$no_returns){
if($weekid<=6){
$todayweek = date("D");
$myarr=array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
for($k=0;$k<=6;$k++){
if ($todayweek==$myarr[$k]){
if($k==0){
$currentdate=0;
}else{
$currentdate=$k;
}
}
}
//get Dateid ----------------
if($Dateid==0){
$Newmyday=date("d")-$currentdate;
}else if ($Dateid==1){
$Newmyday=date("d")-($currentdate-1);
}else if ($Dateid==2){
$Newmyday=date("d")-($currentdate-2);
}else if ($Dateid==3){
$Newmyday=date("d")-($currentdate-3);
}else if ($Dateid==4){
$Newmyday=date("d")-($currentdate-4);
}else if ($Dateid==5){
$Newmyday=date("d")-($currentdate-5);
}else if ($Dateid==6){
$Newmyday=date("d")-($currentdate-6);
}
$thisweekId=$weekid;
$count=0;
$column=0;
$myval=$no_returns*5;
for($i=1; $i<=$myval; $i++){
$week1a = mktime(0, 0, 0, date("m"), $Newmyday, date("Y"));
$week123=strftime("%Y-%m-%d", $week1a);
$Newmyday=$Newmyday+7;
list ($iyear, $imonth, $idate) = split ('[-.-]', $week123);
//Insert Dates into Array
if( $idate<10){
$idate=trim(str_replace('0','',$idate));
}
$myweekno=ceil(($idate + date("w",mktime(0,0,0,$imonth,0,$iyear)))/7);
$row=$myweekno-1;
$Mymonth[$i]=$imonth;
if ($i>1){
if ($Mymonth[$i-1]!=$Mymonth[$i]){
$column=$column+1;
}
}
$EveDates[$row][$column]=$week123;
}
$count=0;
for ( $column = 0; $column < $no_returns; $column++ ){ //--for1-----
$mynewcount=0;
for($row = 0; $row < 6; $row++){ //--for2-----
if($EveDates[$row][$column]!="" && $thisweekId!=6){
list ($iyear1, $imonth1, $idate1) = split ('[-.-]', $EveDates[$row][$column]);
$myweekno=ceil(($idate1 + date("w",mktime(0,0,0,$imonth1,0,$iyear1)))/7);
if($myweekno==$thisweekId+1){
$week_n1= mktime(0, 0, 0, date("m"), date("d"), date("Y"));
$week_m1=strftime("%Y-%m-%d", $week_n1);
if($count < $no_returns && $EveDates[$row][$column] >= $week_m1){
$mydates_array[$count]=$EveDates[$row][$column];
}
$count=$count+1;
}
}
else{
$mycount=0;
if ($row==5 && $thisweekId==6){
for($e=5; $e>=0; $e--){
if($EveDates[$e][$column]!=""){
break;
}
}
$week_n1= mktime(0, 0, 0, date("m"), date("d"), date("Y"));
$week_m1=strftime("%Y-%m-%d", $week_n1);
if($mycount<$no_returns && $EveDates[$e][$column] >= $week_m1){
$mydates_array[$count]=$EveDates[$e][$column];
}
$mycount=$mycount+1;
$count=$count+1;
}
}
} //--End of for2-----
} //--End of for1-----
return $mydates_array;
}else{
echo('WeekID Cant be more than six!');
}}
?>
<select name="eventDate" style="border:1 solid #000066" >
<? // Return 10 Every 2nd Monday dates
$myarray=mydates_array(6,5,10);
for ($i=0;$i<count($myarray);$i++){
list ($iyear, $imonth, $idate) = split ('[-.-]', $myarray[$i]);
$week1a = mktime(0, 0, 0,$imonth, $idate, $iyear);
$week= strftime("%A %d %B %Y", $week1a);
?>
<option value="<?=$myarray[$i]?>"><?=$week?></option>
<? }?>
</select>
msajko at gmail dot com
19-Oct-2005 04:25
array_to_string and sister function string_to_array with multi dimensional array support.
// Converts an array to a string that is safe to pass via a URL
function array_to_string($array) {
$retval = '';
$null_value = "^^^";
foreach ($array as $index => $val) {
if(gettype($val)=='array') $value='^^array^'.array_to_string($val); else $value=$val;
if (!$value)
$value = $null_value;
$retval .= urlencode(base64_encode($index)) . '|' . urlencode(base64_encode($value)) . '||';
}
return urlencode(substr($retval, 0, -2));
}
// Converts a string created by array_to_string() back into an array.
function string_to_array($string) {
$retval = array();
$string = urldecode($string);
$tmp_array = explode('||', $string);
$null_value = urlencode(base64_encode("^^^"));
foreach ($tmp_array as $tmp_val) {
list($index, $value) = explode('|', $tmp_val);
$decoded_index = base64_decode(urldecode($index));
if($value != $null_value){
$val= base64_decode(urldecode($value));
if(substr($val,0,8)=='^^array^') $val=string_to_array(substr($val,8));
$retval[$decoded_index]=$val;
}
else
$retval[$decoded_index] = NULL;
}
return $retval;
}
phpnet_spam at erif dot org
18-Oct-2005 09:36
Thought this might save someone a few hours. :) Feedback welcome, of course! Public domain, yadda yadda.
function assocSort(&$array,$key) {
if (!is_array($array) || count($array) == 0) return true;
$assocSortCompare = '$a = $a["'.$key.'"]; $b = $b["'.$key.'"];';
if (is_numeric($array[0][$key])) {
$assocSortCompare.= ' return ($a == $b) ? 0 : (($a < $b) ? -1 : 1);';
} else {
$assocSortCompare.= ' return strcmp($a,$b);';
}
$assocSortCompare = create_function('$a,$b',$assocSortCompare);
return usort($array,$assocSortCompare);
}
designatevoid at gmail dot com
14-Oct-2005 09:40
Here's an improvement to the array_to_string and string_to_array functions posted by daenders AT yahoo DOT com above.
They now handle NULL values correctly.
<?php
// Converts an array to a string that is safe to pass via a URL
function array_to_string($array) {
$retval = '';
$null_value = "^^^";
foreach ($array as $index => $value) {
if (!$value)
$value = $null_value;
$retval .= urlencode(base64_encode($index)) . '|' . urlencode(base64_encode($value)) . '||';
}
return urlencode(substr($retval, 0, -2));
}
// Converts a string created by array_to_string() back into an array.
function string_to_array($string) {
$retval = array();
$string = urldecode($string);
$tmp_array = explode('||', $string);
$null_value = urlencode(base64_encode("^^^"));
foreach ($tmp_array as $tmp_val) {
list($index, $value) = explode('|', $tmp_val);
$decoded_index = base64_decode(urldecode($index));
if($value != $null_value)
$retval[$decoded_index] = base64_decode(urldecode($value));
else
$retval[$decoded_index] = NULL;
}
return $retval;
}
?>
za at lombardiacom dot it
27-Sep-2005 11:01
<?php
// Swap 2 elements in array preserving keys.
function array_swap(&$array,$key1,$key2) {
$v1=$array[$key1];
$v2=$array[$key2];
$out=array();
foreach($array as $i=>$v) {
if($i==$key1) {
$i=$key2;
$v=$v2;
} else if($i==$key2) {
$i=$key1;
$v=$v1;
}
$out[$i]=$v;
}
return $out;
}
// Move an element inside an array preserving keys.
function array_move(&$array,$key,$position) {
$from=array_search($key,array_keys($array));
$to=$from+$position;
$tot=count($array);
if($position>0) $to++;
if($to<0) $to=0;
else if($to>=$tot) $to=$tot-1;
$n=0;
$out=array();
foreach($array as $i=>$v) {
if($n==$to) $out[$key]=$array[$key];
if($n++==$from) continue;
$out[$i]=$v;
}
return $out;
}
?>
Domenic Denicola
16-Aug-2005 02:49
Another JavaScript conversion, this time to objects instead of arrays. They can be accessed the same way, but are declared much shorter, so it saves some download time for your users:
<?
function PhpArrayToJsObject($array, $objName)
{
return 'var ' . $objName . ' = ' . PhpArrayToJsObject_Recurse($array) . ";\n";
}
function PhpArrayToJsObject_Recurse($array)
{
// Base case of recursion: when the passed value is not a PHP array, just output it (in quotes).
if(! is_array($array) )
{
// Handle null specially: otherwise it becomes "".
if ($array === null)
{
return 'null';
}
return '"' . $array . '"';
}
// Open this JS object.
$retVal = "{";
// Output all key/value pairs as "$key" : $value
// * Output a JS object (using recursion), if $value is a PHP array.
// * Output the value in quotes, if $value is not an array (see above).
$first = true;
foreach($array as $key => $value)
{
// Add a comma before all but the first pair.
if (! $first )
{
$retVal .= ', ';
}
$first = false;
// Quote $key if it's a string.
if (is_string($key) )
{
$key = '"' . $key . '"';
}
$retVal .= $key . ' : ' . PhpArrayToJsObject_Recurse($value);
}
// Close and return the JS object.
return $retVal . "}";
}
?>
Difference from previous function: null values are no longer "" in the object, they are JavaScript null.
So for example:
<?
$theArray = array("A" => array("a", "b", "c" => array("x")), "B" => "y");
echo PhpArrayToJsObject($theArray, "myArray");
?>
Gives:
var myArray = {"A" : {0 : "a", 1 : "b", "c" : {0 : "x"}}, "B" : "y"};
You can still access them just like arrays, with myArray["A"][0] or myArray["A"]["c"][0] or whatever. Just shrinks your pages.
dieter peeters
11-Aug-2005 07:35
in response to: Domenic Denicola
I reworked your function a bit and thought i just as well could post it.
Below is the cleaner version, just cut and paste ;) The third parameter is of little use to the coder, unless javascript declaration of variables changes at some point in the future - who knows.
Only minor point is the added param
|