Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 7th July 2012, 15:28
iseekagain iseekagain is offline
Junior Member
 
Join Date: Jul 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default PHP5 Fill an array with test data.

Hi Everyone,

Need some help to create an array of values ranging from "a" to "zzzzz" but have no idea where to start or look for guidance on this .

Ideally multidimensional array under 1 letter, 2 letters, 3 letters, 4 letters and finally 5 letters.

Can someone point me in the right direction ?

Thanks in advance.
Reply With Quote
Sponsored Links
  #2  
Old 16th August 2012, 09:35
arp arp is offline
Junior Member
 
Join Date: Apr 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default can be solved using loops

If I understand you correctly, this should work fine..

PHP Code:

$alphabet 
range('a''z');
$array = array();

for ( 
$i 1$i 6$i++ ) {
    foreach( 
$alphabet as $item ) {
        
$array[$i][$item] = str_repeat$item$i );
    }
}

# show debug ouptut
print_r $array ); 


which outputs

Code:
Array
(
    [1] => Array
        (
            [a] => a
            [b] => b
            [c] => c
            [d] => d
.....
    [2] => Array
        (
            [a] => aa
            [b] => bb
            [c] => cc
            [d] => dd
            [e] => ee
            [f] => ff
            [g] => gg
            [h] => hh
            [i] => ii
            [j] => jj
            [k] => kk
            [l] => ll
            [m] => mm
            [n] => nn
            [o] => oo
....
Reply With Quote
  #3  
Old 24th October 2012, 01:25
Qzey Qzey is offline
Junior Member
 
Join Date: Oct 2012
Location: Istanbul,TR
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Thumbs up

or you can use this method -> http://php.net/manual/en/function.array-fill.php
Reply With Quote
The Following User Says Thank You to Qzey For This Useful Post:
davince (19th December 2012)
  #4  
Old 12th April 2013, 20:27
sjau sjau is offline
Local Meanie
 
Join Date: Apr 2006
Location: Switzerland
Posts: 1,146
Thanks: 4
Thanked 55 Times in 51 Posts
Default

I know I'm a bit late, but I like this function to display arrays:

Code:
function displayArray($aArray)
{
    if (is_array($aArray) && (count($aArray) > 0))
    {
        print("<table border=1>");
        print("<tr><th>Key</th><th>Value</th></tr>");
            foreach ($aArray as $aKey => $aValue)
            {
                print("<tr>");
                if (!is_array($aValue))
                {
                    if (empty($aValue))
                    {
                        print("<td>$aKey</td><td><i>$aValue</i></td>");
                    } else {
                        print("<td>$aKey</td><td>$aValue</td>");
                    }
                } else {
                    print("<td>$aKey(array)</td><td>");
                    displayArray($aValue);
                    print("</td>");
                }
                print("</tr>");
            }
        print("</table>");
    } else {
        print("<i>empty or invalid</i>");
    }
}
__________________
"Common sense is not as common as commonly believed" by sjau

Auto-Install Script for ISPConfig and Horde on a Vanilla Debian Stable

Need more Repos for Ubuntu? Repository Generator
Need more Repos for Debian? Debian Repository Generator
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with send/ receive mail in ISPconfig freesqrt Installation/Configuration 20 12th July 2012 03:43
ffmpeg Video support for ubuntu 7.10 [suphp-ispconfig] amaurib Installation/Configuration 13 16th February 2010 17:26
Postfix not... doing anything. torg HOWTO-Related Questions 2 18th January 2010 00:46
FFMPEG maybe not an php library? Mkipz Installation/Configuration 2 14th September 2009 21:13
log files, rotation and emailing them hairydog2 General 65 11th October 2006 13:18


All times are GMT +2. The time now is 21:09.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.