/    Sign up×
Community /Pin to ProfileBookmark

Is My Array Conclusions True ?

Hi,

Is my conclusion correct ?

CONCLUSION:

  • 1. If array (full) is turned into variable $ then offset must be inside the same bracket.

  • 2. If array (full) is NOT turned into variable $ then it must be quoted. And, offset must be in a separate bracket.
  • [code]
    <?php
    $string = ‘full[]=title&title=mrs&full[]=first_name&first_name=iris&full[]=surname&surname=alison’;

    parse_str($string);

    echo $arr[‘full'[0]]; //Outputs: Notice: Undefined index: f in ..
    echo $arr[‘full[0]’]; //Outputs: Notice: Undefined index: full[0] in ..
    echo $arr[‘full’][0]; //Outputs: title. Outputs: Array Key.

    echo $arr[“full”[0]]; //Outputs: Notice: Undefined index: f in ..
    echo $arr[“full[0]”]; //Outputs: Notice: Undefined index: full[0] in ..
    echo $arr[“full”][0]; //Outputs: title. Outputs: Array Key.

    echo $arr[$full][0]; //Outputs: Warning: Illegal offset type in ..
    echo $arr[$full[0]]; //Outputs: mrs. Outputs: Array Value.
    ?>
    [/code]

    to post a comment
    PHP

    6 Comments(s)

    Copy linkTweet thisAlerts:
    @developer_webauthorSep 18.2021 — Folks,

    I came to the conclusion after about 3.5hrs of experimenting. Newbies may test too.

    Like this:
    <i>
    </i>&lt;?php
    //parse_str() Test: 1
    $string = 'full[]=title&amp;title=mrs&amp;full[]=first_name&amp;first_name=iris&amp;full[]=surname&amp;surname=alison';

    parse_str($string);

    print_r($string);
    echo '&lt;br&gt;';

    ?&gt;

    &lt;?php
    echo __LINE__; echo '&lt;br&gt;';
    ?&gt;

    &lt;?php
    //parse_str() Test: 2
    $string = 'full[]=title&amp;title=mrs&amp;full[]=first_name&amp;first_name=iris&amp;full[]=surname&amp;surname=alison';

    parse_str($string);

    var_dump($string);
    echo '&lt;br&gt;';

    ?&gt;

    &lt;?php
    echo __LINE__; echo '&lt;br&gt;';
    ?&gt;


    &lt;?php
    //parse_str() Test: 3
    $string = 'full[]=title&amp;title=mrs&amp;full[]=first_name&amp;first_name=iris&amp;full[]=surname&amp;surname=alison';

    parse_str($string,$arr);

    print_r($arr);
    echo '&lt;br&gt;';

    ?&gt;

    &lt;?php
    echo __LINE__; echo '&lt;br&gt;';
    ?&gt;

    &lt;?php
    //parse_str() Test: 4
    $string = 'full[]=title&amp;title=mrs&amp;full[]=first_name&amp;first_name=iris&amp;full[]=surname&amp;surname=alison';

    parse_str($string,$arr);

    var_dump($arr);
    echo '&lt;br&gt;';

    ?&gt;

    &lt;?php
    echo __LINE__; echo '&lt;br&gt;';
    ?&gt;



    &lt;?php
    //parse_str() Test: 5
    //To output: Array Key.
    $string = 'full[]=title&amp;title=mrs&amp;full[]=first_name&amp;first_name=iris&amp;full[]=surname&amp;surname=alison';

    parse_str($string); //Turns Array Keys into Variables.

    echo $full[0]; //Outputs Array Key: title
    echo '&lt;br&gt;';
    echo $full['0']; //Outputs Array Key: title
    echo '&lt;br&gt;';
    echo $full["0"]; //Outputs Array Key: title
    echo '&lt;br&gt;';
    echo $full{0}; //Outputs Array Key: title
    echo '&lt;br&gt;';
    echo $full{'0'}; //Outputs Array Key: title
    echo '&lt;br&gt;';
    echo $full{"0"}; //Outputs Array Key: title
    echo '&lt;br&gt;';

    ?&gt;

    &lt;?php
    echo __LINE__; echo '&lt;br&gt;';
    ?&gt;

    &lt;?php
    //parse_str() Test: 6
    //To output: Array Value.
    $string = 'full[]=title&amp;title=mrs&amp;full[]=first_name&amp;first_name=iris&amp;full[]=surname&amp;surname=alison';

    parse_str($string,$arr);

    echo $arr[$full[0]]; //Outputs Array Value: mrs
    echo '&lt;br&gt;';
    echo $arr[$full['0']]; //Outputs Array Value: mrs
    echo '&lt;br&gt;';
    echo $arr[$full["0"]]; //Outputs Array Value: mrs
    echo '&lt;br&gt;';
    echo $arr[$full{0}]; //Outputs Array Value: mrs
    echo '&lt;br&gt;';
    echo $arr[$full{'0'}]; //Outputs Array Value: mrs
    echo '&lt;br&gt;';
    echo $arr[$full{"0"}]; //Outputs Array Value: mrs
    echo '&lt;br&gt;';

    ?&gt;

    &lt;?php
    echo __LINE__; echo '&lt;br&gt;';
    ?&gt;

    &lt;?php
    //parse_str() Test: 7
    //To output: Array Value.
    $string = 'full[]=title&amp;title=mrs&amp;full[]=first_name&amp;first_name=iris&amp;full[]=surname&amp;surname=alison';

    parse_str($string,$arr);

    echo $arr{$full[0]}; //Outputs Array Value: mrs
    echo '&lt;br&gt;';
    echo $arr{$full['0']}; //Outputs Array Value: mrs
    echo '&lt;br&gt;';
    echo $arr{$full["0"]}; //Outputs Array Value: mrs
    echo '&lt;br&gt;';
    echo $arr{$full{0}}; //Outputs Array Value: mrs
    echo '&lt;br&gt;';
    echo $arr{$full{'0'}}; //Outputs Array Value: mrs
    echo '&lt;br&gt;';
    echo $arr{$full{"0"}}; //Outputs Array Value: mrs
    echo '&lt;br&gt;';

    ?&gt;

    &lt;?php
    echo __LINE__; echo '&lt;br&gt;';
    ?&gt;

    &lt;?php
    //parse_str() Test: 8
    //To output: Array Value.
    $string = 'full[]=title&amp;title=mrs&amp;full[]=first_name&amp;first_name=iris&amp;full[]=surname&amp;surname=alison';

    parse_str($string,$arr);

    echo $arr[$full][0]; //Outputs: Warning: Illegal offset type in ..
    echo '&lt;br&gt;';
    echo $arr[$full]['0']; //Outputs: Warning: Illegal offset type in ..
    echo '&lt;br&gt;';
    echo $arr[$full]["0"]; //Outputs: Warning: Illegal offset type in ..
    echo '&lt;br&gt;';
    echo $arr[$full]{0}; //Outputs: Warning: Illegal offset type in ..
    echo '&lt;br&gt;';
    echo $arr[$full]{'0'}; //Outputs: Warning: Illegal offset type in ..
    echo '&lt;br&gt;';
    echo $arr[$full]{"0"}; //Outputs: Warning: Illegal offset type in ..
    echo '&lt;br&gt;';

    ?&gt;

    &lt;?php
    echo __LINE__; echo '&lt;br&gt;';
    ?&gt;

    &lt;?php
    //parse_str() Test: 9
    //To output: Array Value.
    $string = 'full[]=title&amp;title=mrs&amp;full[]=first_name&amp;first_name=iris&amp;full[]=surname&amp;surname=alison';

    parse_str($string,$arr);

    echo $arr{$full}[0]; //Outputs: Warning: Illegal offset type in ..
    echo '&lt;br&gt;';
    echo $arr{$full}['0']; //Outputs: Warning: Illegal offset type in ..
    echo '&lt;br&gt;';
    echo $arr{$full}["0"]; //Outputs: Warning: Illegal offset type in ..
    echo '&lt;br&gt;';
    echo $arr{$full}{0}; //Outputs: Warning: Illegal offset type in ..
    echo '&lt;br&gt;';
    echo $arr{$full}{'0'}; //Outputs: Warning: Illegal offset type in ..
    echo '&lt;br&gt;';
    echo $arr{$full}{"0"}; //Outputs: Warning: Illegal offset type in ..
    echo '&lt;br&gt;';

    ?&gt;

    &lt;?php
    echo __LINE__; echo '&lt;br&gt;';
    ?&gt;

    &lt;?php
    //parse_str() Test: 10
    //To output: Array Value.
    $string = 'full[]=title&amp;title=mrs&amp;full[]=first_name&amp;first_name=iris&amp;full[]=surname&amp;surname=alison';

    parse_str($string,$arr);

    echo $arr['full[0]']; //Outputs: Notice: Undefined index: full[0] in ..
    echo '&lt;br&gt;';
    echo $arr['full['0']']; //Outputs: Notice: Undefined index: full['0'] in ..
    echo '&lt;br&gt;';
    echo $arr['full["0"]']; //Outputs: Notice: Undefined index: full["0"] in ..
    echo '&lt;br&gt;';
    echo $arr['full{0}']; //Outputs: Notice: Undefined index: full{0} in ..
    echo '&lt;br&gt;';
    echo $arr['full{'0'}']; //Outputs: Notice: Undefined index: full{'0'} in ..
    echo '&lt;br&gt;';
    echo $arr['full{"0"}']; //Outputs: Notice: Undefined index: full{"0"} in ..
    echo '&lt;br&gt;';

    ?&gt;

    &lt;?php
    echo __LINE__; echo '&lt;br&gt;';
    ?&gt;

    &lt;?php
    //parse_str() Test: 11
    //To output: Array Value.
    $string = 'full[]=title&amp;title=mrs&amp;full[]=first_name&amp;first_name=iris&amp;full[]=surname&amp;surname=alison';

    parse_str($string,$arr);

    echo $arr{'full[0]'}; //Outputs: Notice: Undefined index: full[0] in ..
    echo '&lt;br&gt;';
    echo $arr{'full['0']'}; //Outputs: Notice: Undefined index: full['0'] in ..
    echo '&lt;br&gt;';
    echo $arr{'full["0"]'}; //Outputs: Notice: Undefined index: full["0"] in ..
    echo '&lt;br&gt;';
    echo $arr{'full{0}'}; //Outputs: Notice: Undefined index: full{0} in ..
    echo '&lt;br&gt;';
    echo $arr{'full{'0'}'}; //Outputs: Notice: Undefined index: full{'0'} in ..
    echo '&lt;br&gt;';
    echo $arr{'full{"0"}'}; //Outputs: Notice: Undefined index: full{"0"} in ..
    echo '&lt;br&gt;';

    ?&gt;

    &lt;?php
    echo __LINE__; echo '&lt;br&gt;';
    ?&gt;

    &lt;?php
    //parse_str() Test: 12
    //To output: Array Value.
    $string = 'full[]=title&amp;title=mrs&amp;full[]=first_name&amp;first_name=iris&amp;full[]=surname&amp;surname=alison';

    parse_str($string,$arr);

    echo $arr['full'][0]; //Outputs: title
    echo '&lt;br&gt;';
    echo $arr['full']['0']; //Outputs: Outputs: title
    echo '&lt;br&gt;';
    echo $arr['full']["0"]; //Outputs: Outputs: title
    echo '&lt;br&gt;';
    echo $arr['full']{0}; //Outputs: Outputs: title
    echo '&lt;br&gt;';
    echo $arr['full']{'0'}; //Outputs: Outputs: title
    echo '&lt;br&gt;';
    echo $arr['full']{"0"}; //Outputs: Outputs: title
    echo '&lt;br&gt;';

    ?&gt;

    &lt;?php
    echo __LINE__; echo '&lt;br&gt;';
    ?&gt;

    &lt;?php
    //parse_str() Test: 13
    //To output: Array Value.
    $string = 'full[]=title&amp;title=mrs&amp;full[]=first_name&amp;first_name=iris&amp;full[]=surname&amp;surname=alison';

    parse_str($string,$arr);

    echo $arr{'full'}[0]; //Outputs: title
    echo '&lt;br&gt;';
    echo $arr{'full'}['0']; //Outputs: Outputs: title
    echo '&lt;br&gt;';
    echo $arr{'full'}["0"]; //Outputs: Outputs: title
    echo '&lt;br&gt;';
    echo $arr{'full'}{0}; //Outputs: Outputs: title
    echo '&lt;br&gt;';
    echo $arr{'full'}{'0'}; //Outputs: Outputs: title
    echo '&lt;br&gt;';
    echo $arr{'full'}{"0"}; //Outputs: Outputs: title
    echo '&lt;br&gt;';

    ?&gt;

    &lt;?php
    echo __LINE__; echo '&lt;br&gt;';
    ?&gt;

    &lt;?php
    //parse_str() Test: 14
    //To output: Array Value.
    $string = 'full[]=title&amp;title=mrs&amp;full[]=first_name&amp;first_name=iris&amp;full[]=surname&amp;surname=alison';

    parse_str($string,$arr);

    //Notice: Undefined index: f in ..
    echo ${$arr['full'[0]]}; //Outputs: Notice: Undefined variable: in ..
    //Notice: Undefined index: full[0] ..
    echo ${$arr['full[0]']}; //Outputs: Notice: Undefined variable: in ..
    echo ${$arr['full'][0]}; //Outputs: mrs. Outputs: Array Value.
    //Notice: Undefined index: f in ..
    echo ${$arr["full"[0]]}; //Outputs: //Notice: Undefined variable: in ..
    //Notice: Undefined index: full[0] in ..
    echo ${$arr["full[0]"]}; //Outputs: Notice: Undefined variable: in ..
    echo ${$arr["full"][0]}; //Outputs: mrs. Outputs: Array Value.
    //Warning: Illegal offset type in ..
    echo ${$arr[$full][0]}; //Outputs: Notice: Undefined variable: in ..
    echo ${$arr[$full[0]]}; //Outputs: Notice: Undefined variable: mrs in ..

    ?&gt;

    &lt;?php
    echo __LINE__; echo '&lt;br&gt;';
    ?&gt;

    &lt;?php
    //parse_str() Test: 15
    //To output: Array Value.
    $string = 'full[]=title&amp;title=mrs&amp;full[]=first_name&amp;first_name=iris&amp;full[]=surname&amp;surname=alison';

    parse_str($string,$arr);

    echo $[$arr{'full'[0]}]; //Outputs: Parse error: syntax error, unexpected '[', expecting variable (T_VARIABLE) or '{' or '$' in ..
    echo $[$arr{'full[0]'}]; //Outputs: Parse error: syntax error, unexpected '[', expecting variable (T_VARIABLE) or '{' or '$' in ..
    echo $[$arr{'full'}[0]]; //Outputs: Parse error: syntax error, unexpected '[', expecting variable (T_VARIABLE) or '{' or '$' in ..
    echo $[$arr{"full"[0]}]; //Outputs: Parse error: syntax error, unexpected '[', expecting variable (T_VARIABLE) or '{' or '$' in ..
    echo $[$arr{"full[0]"}]; //Outputs: Parse error: syntax error, unexpected '[', expecting variable (T_VARIABLE) or '{' or '$' in ..
    echo $[$arr{"full"}[0]]; //Outputs: Parse error: syntax error, unexpected '[', expecting variable (T_VARIABLE) or '{' or '$' in ..
    echo $[$arr{$full}[0]]; //Outputs: Parse error: syntax error, unexpected '[', expecting variable (T_VARIABLE) or '{' or '$' in ..
    echo $[$arr{$full[0]}]; //Outputs: Parse error: syntax error, unexpected '[', expecting variable (T_VARIABLE) or '{' or '$' in ..
    ?&gt;

    &lt;?php
    echo __LINE__; echo '&lt;br&gt;';
    ?&gt;

    &lt;?php
    //parse_str() Test: 16
    //CONCLUSION:
    //1. If array (full) is turned into variable $ then offset must be inside the same bracket.
    //2. If array (full) is NOT turned into variable $ then it must be quoted. And, offset must be in a separate bracket.

    //To output: Array Value.
    $string = 'full[]=title&amp;title=mrs&amp;full[]=first_name&amp;first_name=iris&amp;full[]=surname&amp;surname=alison';

    parse_str($string,$arr);

    echo $arr['full'[0]]; //Outputs: Notice: Undefined index: f in ..
    echo $arr['full[0]']; //Outputs: Notice: Undefined index: full[0] in ..
    echo $arr['full'][0]; //Outputs: title. Outputs: Array Key.

    echo $arr["full"[0]]; //Outputs: Notice: Undefined index: f in ..
    echo $arr["full[0]"]; //Outputs: Notice: Undefined index: full[0] in ..
    echo $arr["full"][0]; //Outputs: title. Outputs: Array Key.

    echo $arr[$full][0]; //Outputs: Warning: Illegal offset type in ..
    echo $arr[$full[0]]; //Outputs: mrs. Outputs: Array Value.

    ?&gt;

    &lt;?php
    echo __LINE__; echo '&lt;br&gt;';
    ?&gt;

    Copy linkTweet thisAlerts:
    @NogDogSep 18.2021 — I think what you want is:
    [code=php]
    $string = 'full[title]=mrs&full[first_name]=iris&full[surname]=alison';
    parse_str($string, $result);
    printf(
    "The full name is %s %s %s",
    ucfirst(strtolower($result['full']['title'])),
    ucfirst(strtolower($result['full']['first_name'])),
    ucfirst(strtolower($result['full']['surname']))
    );

    // Output:
    // The full name is Mrs Iris Alison
    [/code]
    Copy linkTweet thisAlerts:
    @developer_webauthorSep 21.2021 — @NogDog#1637217

    Thanks for the code on how to echo things. But that's not what I really was trying to do. I was experimenting and trying to figure how php does things. I came to this following conclusion. I opened this thread to learn if my conclusion is spot-on or not and so I'd appreciate if you let me know if I am spot on or not.

    **CONCLUSION:

    If array (full) is turned into variable $ then offset must be inside the same bracket.

    If array (full) is NOT turned into variable $ then it must be quoted. And, offset must be in a separate bracket.**

    If you are confused then check my op and my previous post that shows my experiment.
    Copy linkTweet thisAlerts:
    @developer_webauthorSep 22.2021 — @ginerjm

    Do you mind letting me know about my conclusion above ?

    What do you think ? Percentage-wise, how spot-on was I ?
    Copy linkTweet thisAlerts:
    @ginerjmSep 22.2021 — I have no interest in this topic. Learn from that. If you have a question post the question and the code that is giving you that question. Stop posting these theoretical nonsensical things. We're here to help, not necessarily to teach. You will learn from the answers we provide to your genuine problems. Our time is wasted otherwise.
    Copy linkTweet thisAlerts:
    @developer_webauthorSep 22.2021 — @ginerjm#1637450

    I did some experiments. I came to a conclusion from my code research. Asked you seniors to let me know if my conclusion was correct or not. If you say, it is correct, then I learnt something and stick to what I learnt. Else, I quit learning my findings. I empty my cup and pour out the bad tea.

    That's all.

    What's the harm in that ?
    ×

    Success!

    Help @developer_web spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 4.25,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...