Results 1 to 9 of 9

Thread: [RESOLVED] Array Help

  1. #1

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Resolved [RESOLVED] Array Help

    I'm setting up a forum for our company and I'm trying to extract some information from an array but not having any luck. If I use the below to display the array, the information I want to extract is '[icon_url]'

    Can anyone help me?

    PHP Code:
    print_r($context['get_message']()); 
    Array ( [attachment] => Array ( ) [alternate] => 0 [id] => 3 [href] => http://localhost/blog/index.php?topic=2.msg3#msg3 [link] => [RESOLVED]subject [member] => Array ( [username] => Mark [name] => Mark [id] => 2 [is_guest] => [is_buddy] => [is_reverse_buddy] => [buddies] => Array ( ) [title] => [href] => http://localhost/blog/index.php?action=profile;u=2 [link] => Mark [email] => [email protected] [hide_email] => [email_public] => 1 [registered] => March 20, 2007, 07:09:10 pm [registered_timestamp] => 1174378150 [blurb] => [gender] => Array ( [name] => [image] => ) [website] => Array ( [title] => [url] => ) [birth_date] => 0000-00-00 [signature] => [location] => [icq] => Array ( [name] => [add] => [href] => [link] => [link_text] => ) [aim] => Array ( [name] => [href] => [link] => [link_text] => ) [yim] => Array ( [name] => [href] => [link] => [link_text] => ) [msn] => Array ( [name] => [href] => [link] => [link_text] => ) [real_posts] => 5 [posts] => 5 [avatar] => Array ( [name] => [image] => [href] => [url] => ) [last_login] => Today at 09:32:24 pm [last_login_timestamp] => 1174559544 [karma] => Array ( [good] => 1 [bad] => 1 [allow] => ) [ip] => 127.0.0.1 [ip2] => 127.0.0.1 [online] => Array ( [is_online] => 1 [text] => Online [href] => http://localhost/blog/index.php?action=pm;sa=send;u=2 [link] => Online [image_href] => http://localhost/blog/Themes/default/images/useron.gif [label] => Personal Message (Online) ) [language] => [is_activated] => 1 [is_banned] => [options] => Array ( [show_board_desc] => 1 [show_children] => 0 [show_no_avatars] => 0 [show_no_signatures] => 0 [return_to_post] => 1 [no_new_reply_warning] => 0 [view_newest_first] => 0 [view_newest_pm_first] => 0 [calendar_start_day] => 0 [display_quick_reply] => 0 [display_quick_mod] => 0 [auto_notify] => 1 [collapse_header] => 1 ) [group] => [group_color] => [group_id] => 0 [post_group] => Newbie [post_group_color] => [group_stars] => [local_time] => March 22, 2007, 09:32:31 pm [can_view_profile] => 1 [is_topic_starter] => 1 ) [icon] => solved [icon_url] => http://localhost/blog/Themes/default/images/post/solved.gif [subject] => [RESOLVED]subject [time] => March 20, 2007, 07:29:28 pm [timestamp] => 1174379368 [counter] => 0 [modified] => Array ( [time] => January 01, 1970, 11:00:00 am [timestamp] => 0 [name] => ) [body] => Test

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

    Re: Array Help

    Use your browsers view source or send a plain text header so you can see the output of print_r formatted with whitespace.
    PHP Code:
    header('Content-Type: text/plain');
    print_r($context['get_message']()); 
    You can access arrays within arrays by using a format similar to this:
    PHP Code:
    $value $array1['innerArray']['index']; 
    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.

  3. #3

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Array Help

    Thanks visualAd for the tip on the browsers.

    Below is what is displayed but I still can't get the [icon_url] information?

    HTML Code:
    Array
    (
        [attachment] => Array
            (
            )
    
        [alternate] => 0
        [id] => 3
        [href] => http://localhost/blog/index.php?topic=2.msg3#msg3
        [link] => <a href="http://localhost/blog/index.php?topic=2.msg3#msg3">[RESOLVED]subject</a>
        [member] => Array
            (
                [username] => Mark
                [name] => Mark
                [id] => 2
                [is_guest] => 
                [is_buddy] => 
                [is_reverse_buddy] => 
                [buddies] => Array
                    (
                    )
    
                [title] => 
                [href] => http://localhost/blog/index.php?action=profile;u=2
                [link] => <a href="http://localhost/blog/index.php?action=profile;u=2" title="View the profile of Mark">Mark</a>
                [email] => [email protected]
                [hide_email] => 
                [email_public] => 1
                [registered] => March 20, 2007, 07:09:10 pm
                [registered_timestamp] => 1174378150
                [blurb] => 
                [gender] => Array
                    (
                        [name] => 
                        [image] => 
                    )
    
                [website] => Array
                    (
                        [title] => 
                        [url] => 
                    )
    
                [birth_date] => 0000-00-00
                [signature] => 
                [location] => 
                [icq] => Array
                    (
                        [name] => 
                        [add] => 
                        [href] => 
                        [link] => 
                        [link_text] => 
                    )
    
                [aim] => Array
                    (
                        [name] => 
                        [href] => 
                        [link] => 
                        [link_text] => 
                    )
    
                [yim] => Array
                    (
                        [name] => 
                        [href] => 
                        [link] => 
                        [link_text] => 
                    )
    
                [msn] => Array
                    (
                        [name] => 
                        [href] => 
                        [link] => 
                        [link_text] => 
                    )
    
                [real_posts] => 5
                [posts] => 5
                [avatar] => Array
                    (
                        [name] => 
                        [image] => 
                        [href] => 
                        [url] => 
                    )
    
                [last_login] => <b>Today</b> at 10:14:51 pm
                [last_login_timestamp] => 1174562091
                [karma] => Array
                    (
                        [good] => 1
                        [bad] => 1
                        [allow] => 
                    )
    
                [ip] => 127.0.0.1
                [ip2] => 127.0.0.1
                [online] => Array
                    (
                        [is_online] => 1
                        [text] => Online
                        [href] => http://localhost/blog/index.php?action=pm;sa=send;u=2
                        [link] => <a href="http://localhost/blog/index.php?action=pm;sa=send;u=2">Online</a>
                        [image_href] => http://localhost/blog/Themes/default/images/useron.gif
                        [label] => Personal Message (Online)
                    )
    
                [language] => 
                [is_activated] => 1
                [is_banned] => 
                [options] => Array
                    (
                        [show_board_desc] => 1
                        [show_children] => 0
                        [show_no_avatars] => 0
                        [show_no_signatures] => 0
                        [return_to_post] => 1
                        [no_new_reply_warning] => 0
                        [view_newest_first] => 0
                        [view_newest_pm_first] => 0
                        [calendar_start_day] => 0
                        [display_quick_reply] => 0
                        [display_quick_mod] => 0
                        [auto_notify] => 1
                        [collapse_header] => 1
                    )
    
                [group] => 
                [group_color] => 
                [group_id] => 0
                [post_group] => Newbie
                [post_group_color] => 
                [group_stars] => <img src="http://localhost/blog/Themes/default/images/star.gif" alt="*" border="0" />
                [local_time] => March 22, 2007, 10:14:51 pm
                [can_view_profile] => 1
                [is_topic_starter] => 1
            )
    
        [icon] => solved
        [icon_url] => http://localhost/blog/Themes/default/images/post/solved.gif
        [subject] => [RESOLVED]subject
        [time] => March 20, 2007, 07:29:28 pm
        [timestamp] => 1174379368
        [counter] => 0
        [modified] => Array
            (
                [time] => January 01, 1970, 11:00:00 am
                [timestamp] => 0
                [name] => 
            )
    If I used the below 'p' is returned?
    PHP Code:
    echo $context['get_message']['icon_url']; 

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

    Re: Array Help

    You should get the URL.

    Can you post the print_r output for $context?
    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.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Array Help

    In your first snippet you're calling $context['get_message'] as a function:
    print_r($context['get_message']());

    But in your second you're not calling the function:
    echo $context['get_message']['icon_url'];

  6. #6

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Array Help

    Below is the output for $context

    HTML Code:
    Array
    (
        [user] => Array
            (
                [id] => 2
                [is_logged] => 1
                [is_guest] => 
                [is_admin] => 
                [is_mod] => 
                [username] => Mark
                [language] => english
                [email] => [email protected]
                [name] => Mark
                [smiley_set] => default
                [started] => 1
                [messages] => 0
                [unread_messages] => 0
                [popup_messages] => 
                [avatar] => Array
                    (
                    )
    
                [total_time_logged_in] => Array
                    (
                        [days] => 0
                        [hours] => 4
                        [minutes] => 10
                    )
    
            )
    
        [linktree] => Array
            (
                [0] => Array
                    (
                        [url] => http://localhost/blog/index.php
                        [name] => ShareFinder Forums
                    )
    
                [1] => Array
                    (
                        [url] => http://localhost/blog/index.php#1
                        [name] => General Category
                    )
    
                [2] => Array
                    (
                        [url] => http://localhost/blog/index.php?board=1.0
                        [name] => General Discussion
                    )
    
                [3] => Array
                    (
                        [url] => http://localhost/blog/index.php?topic=2.0
                        [name] => [RESOLVED] Testing
                        [extra_before] => 
                    )
    
            )
    
        [current_topic] => 2
        [current_board] => 1
        [html_headers] => 
        [menu_separator] =>  
        [session_id] => f7dbab8c0ceadf80d15df3d5e9cedc25
        [forum_name] => ShareFinder Forums
        [current_action] => 
        [current_subaction] => 
        [server] => Array
            (
                [is_iis] => 
                [is_apache] => 1
                [is_cgi] => 
                [is_windows] => 1
                [iso_case_folding] => 1
                [complex_preg_chars] => 1
                [needs_login_fix] => 
            )
    
        [browser] => Array
            (
                [is_opera] => 
                [is_opera6] => 
                [is_opera7] => 
                [is_opera8] => 
                [is_ie4] => 
                [is_safari] => 
                [is_mac_ie] => 
                [is_web_tv] => 
                [is_konqueror] => 
                [is_firefox] => 
                [is_firefox1] => 
                [is_firefox2] => 
                [is_gecko] => 
                [is_ie7] => 
                [is_ie6] => 1
                [is_ie5.5] => 
                [is_ie5] => 
                [is_ie] => 1
                [needs_size_fix] => 0
                [possibly_robot] => 
            )
    
        [template_layers] => Array
            (
                [0] => main
            )
    
        [character_set] => ISO-8859-1
        [utf8] => 
        [right_to_left] => 
        [tabindex] => 1
        [previous_next] => <a href="http://localhost/blog/index.php?topic=2.0;prev_next=prev#new">&laquo; previous</a> <a href="http://localhost/blog/index.php?topic=2.0;prev_next=next#new">next &raquo;</a>
        [show_spellchecking] => 
        [page_title] => [RESOLVED] Testing
        [num_replies] => 2
        [topic_first_message] => 3
        [is_marked_notify] => 1
        [page_index] => [<b>1</b>] 
        [start] => 0
        [page_info] => Array
            (
                [current_page] => 1
                [num_pages] => 1
            )
    
        [links] => Array
            (
                [first] => 
                [prev] => 
                [next] => 
                [last] => 
                [up] => http://localhost/blog/index.php?board=1.0
            )
    
        [moderators] => Array
            (
            )
    
        [link_moderators] => Array
            (
            )
    
        [is_locked] => 0
        [is_sticky] => 0
        [is_very_hot] => 
        [is_hot] => 
        [is_poll] => 
        [class] => normal_post
        [extended_class] => normal_post
        [topic_starter_id] => 2
        [subject] => [RESOLVED] Testing
        [num_views] => 5
        [mark_unread_time] => 8
        [response_prefix] => Re: 
        [first_message] => 3
        [first_new_message] => 
        [jump_to] => Array
            (
                [0] => Array
                    (
                        [id] => 1
                        [name] => General Category
                        [boards] => Array
                            (
                                [0] => Array
                                    (
                                        [id] => 2
                                        [name] => New Board
                                        [child_level] => 0
                                        [is_current] => 
                                    )
    
                                [1] => Array
                                    (
                                        [id] => 1
                                        [name] => General Discussion
                                        [child_level] => 0
                                        [is_current] => 1
                                    )
    
                            )
    
                    )
    
            )
    
        [get_message] => prepareDisplayContext
        [allow_hide_email] => 1
        [can_sticky] => 0
        [can_merge] => 
        [can_split] => 
        [calendar_post] => 0
        [can_mark_notify] => 1
        [can_send_topic] => 1
        [can_send_pm] => 1
        [can_report_moderator] => 1
        [can_moderate_forum] => 
        [can_move] => 0
        [can_lock] => 1
        [can_delete] => 1
        [can_add_poll] => 1
        [can_remove_poll] => 0
        [can_reply] => 1
        [can_remove_post] => 
        [news_lines] => Array
            (
                [0] => SMF - Just Installed!
            )
    
        [fader_news_lines] => Array
            (
                [0] => SMF - Just Installed!
            )
    
        [random_news_line] => SMF - Just Installed!
        [allow_search] => 1
        [allow_admin] => 
        [allow_edit_profile] => 1
        [allow_memberlist] => 1
        [allow_calendar] => 
        [allow_pm] => 1
        [in_maintenance] => 
        [current_time] => March 22, 2007, 11:01:15 pm
        [show_quick_login] => 
        [show_news] => 1
        [common_stats] => Array
            (
                [total_posts] => 7
                [total_topics] => 3
                [total_members] => 2
                [latest_member] => Array
                    (
                        [id] => 2
                        [name] => Mark
                        [href] => http://localhost/blog/index.php?action=profile;u=2
                        [link] => <a href="http://localhost/blog/index.php?action=profile;u=2">Mark</a>
                    )
    
            )
    
    )
    Pengate, if I use the below (to call the function) I get an error (forum displays a generic error message).
    PHP Code:
    echo  $context['get_message']()['icon_url']; 

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

    Re: Array Help

    Then you need to use something like this:
    PHP Code:
    $array = array('fart' => array('call' =>'fart'));
    $ret $array['fart']['call']();

    echo(
    $ret['food']);

    function 
    fart()
    {
        return array(
    'food'=>'drink');

    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.

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

    Re: Array Help

    You get a parse error because you cannot use the array access notation on a non variable. You therefore need to assign the result to a temporary variable before accessing it.
    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.

  9. #9

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Resolved Re: Array Help

    Thanks visualAd...

    I solved it by using the below.

    PHP Code:
    $array1 $context['get_message']();
    $icon_url $array1['icon_url']; 

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