Re: list all constitute group of array ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 14 Feb 2009 07:41:28 +0800, ad@xxxxxxxx ("LKSunny") wrote:

><?
>$a = array("a", "b", "c", "d");
>
>/*
>how to list:
>abcd
>abc
>ab
>ac
>ad
>bcd
>bc
>bd
>cd
>a
>b
>c
>d
>
>who have idea ? thank you very much !!
>*/
>?>
>

If you are talking about arrays of strings,use my function larec (list array recursively).
This has proved to be one of the most useful things I have ever written.  The first
parameter is the name of the array (or subsection of an array) you wish to list, and the
second parameter is the arbitrary name used for the array in the listing.  (it would be
quite easy to modify the procedure to use the actual name of the array, but I wrote it
this way, and it is quite handy to be able to use different names if you are listing
different sections of the same array. It will work with an array of almost any complexity.
I have seen it choof out (almost instantly!) several thousand lines.
<?php
// Expand string array, & list all terms
function larec($array, $line) // List array recursive
	{
	if (is_array($array))
		{
		$j = count ($array);
		$temp = array_keys($array);
		$i = 0; while ($i < $j)
			{
			if(isset($array[$temp[$i]]))
				{
				$new_line = $line."['".$temp[$i]."']";
				larec ($array[$temp[$i]], $new_line);
				}
			$i++;
			}
		}
	else
		{
		echo '<p>'.$line.' = '.$array.'</p>';
		}
	}
?>
This is a sample of part of a listing. The call for this would have been 'larec
($wkg_data[$entry], 'Entry');

Entry['phone']['ph_o'] = 9978 4749
Entry['phone']['ph_h'] = 
Entry['phone']['ph_m'] = 
Entry['phone']['ph_f'] = 9978 4516
Entry['phone']['ph_a'] = 02
Entry['phone']['ph_e'] = 
Entry['phone']['ph_w'] = 
Entry['phone']['ph_b'] = 

Entry['bursary']['CY']['b_name'] = Cybec Scholarship
Entry['bursary']['CY']['b_status'] = 
Entry['bursary']['EB']['b_name'] = Evan Burge Scholarship
Entry['bursary']['EB']['b_status'] = 
Entry['bursary']['MAP']['b_name'] = Cybec MAP Scholarship
Entry['bursary']['MAP']['b_status'] = 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux