Results 1 to 4 of 4

Thread: [RESOLVED] Arrays with strings as indexes maybe???

  1. #1

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Resolved [RESOLVED] Arrays with strings as indexes maybe???

    Ok, hard to explain here, and I mix up Python (where there is some really nice things you can do with lists).

    I do n quereries, and from every query I get m words. I want to count how many times each word occours.

    - I don't know what words will occour up front
    - I don't know how many they are


    So how would you go about something like this in PHP. Think about it as a double loop:

    Code:
    //Outer loop, every query
    for ($j = 0; $j < count($queries); $j++){
        //Getting one and one tag
        for ($i = 0; $i < count($tag_array); $i++){
            //Here we need to add them to an array, so we both know what word it is, and how many times it occoured.
            //$tag_array[$i] is now holding one word.
        }
    }

    Hope that was understandable...


    - ØØ -

  2. #2

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Arrays with strings as indexes maybe???

    Got it sorted with some VAD help again..


    I just add them like this:
    Code:
    $tags[$tag_array[$i]] ++;


    and then print them out like this:
    Code:
                        foreach($tags as $key =>$name) {
                            echo 'Hva:' . $key . ':' . $name . ':';
                        }

  3. #3
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: [RESOLVED] Arrays with strings as indexes maybe???

    Smarty also has:

    {foreach from=$arary item="single_element"}
    {/foreach}

    now go to bed
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  4. #4

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: [RESOLVED] Arrays with strings as indexes maybe???

    I havn't tested yet, but I think I have to use a double..


    Code:
    {foreach name=outer item=contact from=$contacts}
      {foreach key=key item=item from=$contact}
        {$key}: {$item}
      {/foreach}
    {/foreach}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width