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.
?>
<i>
</i><?php
//parse_str() Test: 1
$string = 'full[]=title&title=mrs&full[]=first_name&first_name=iris&full[]=surname&surname=alison';
parse_str($string);
print_r($string);
echo '<br>';
?>
<?php
echo __LINE__; echo '<br>';
?>
<?php
//parse_str() Test: 2
$string = 'full[]=title&title=mrs&full[]=first_name&first_name=iris&full[]=surname&surname=alison';
parse_str($string);
var_dump($string);
echo '<br>';
?>
<?php
echo __LINE__; echo '<br>';
?>
<?php
//parse_str() Test: 3
$string = 'full[]=title&title=mrs&full[]=first_name&first_name=iris&full[]=surname&surname=alison';
parse_str($string,$arr);
print_r($arr);
echo '<br>';
?>
<?php
echo __LINE__; echo '<br>';
?>
<?php
//parse_str() Test: 4
$string = 'full[]=title&title=mrs&full[]=first_name&first_name=iris&full[]=surname&surname=alison';
parse_str($string,$arr);
var_dump($arr);
echo '<br>';
?>
<?php
echo __LINE__; echo '<br>';
?>
<?php
//parse_str() Test: 5
//To output: Array Key.
$string = 'full[]=title&title=mrs&full[]=first_name&first_name=iris&full[]=surname&surname=alison';
parse_str($string); //Turns Array Keys into Variables.
echo $full[0]; //Outputs Array Key: title
echo '<br>';
echo $full['0']; //Outputs Array Key: title
echo '<br>';
echo $full["0"]; //Outputs Array Key: title
echo '<br>';
echo $full{0}; //Outputs Array Key: title
echo '<br>';
echo $full{'0'}; //Outputs Array Key: title
echo '<br>';
echo $full{"0"}; //Outputs Array Key: title
echo '<br>';
?>
<?php
echo __LINE__; echo '<br>';
?>
<?php
//parse_str() Test: 6
//To output: Array Value.
$string = 'full[]=title&title=mrs&full[]=first_name&first_name=iris&full[]=surname&surname=alison';
parse_str($string,$arr);
echo $arr[$full[0]]; //Outputs Array Value: mrs
echo '<br>';
echo $arr[$full['0']]; //Outputs Array Value: mrs
echo '<br>';
echo $arr[$full["0"]]; //Outputs Array Value: mrs
echo '<br>';
echo $arr[$full{0}]; //Outputs Array Value: mrs
echo '<br>';
echo $arr[$full{'0'}]; //Outputs Array Value: mrs
echo '<br>';
echo $arr[$full{"0"}]; //Outputs Array Value: mrs
echo '<br>';
?>
<?php
echo __LINE__; echo '<br>';
?>
<?php
//parse_str() Test: 7
//To output: Array Value.
$string = 'full[]=title&title=mrs&full[]=first_name&first_name=iris&full[]=surname&surname=alison';
parse_str($string,$arr);
echo $arr{$full[0]}; //Outputs Array Value: mrs
echo '<br>';
echo $arr{$full['0']}; //Outputs Array Value: mrs
echo '<br>';
echo $arr{$full["0"]}; //Outputs Array Value: mrs
echo '<br>';
echo $arr{$full{0}}; //Outputs Array Value: mrs
echo '<br>';
echo $arr{$full{'0'}}; //Outputs Array Value: mrs
echo '<br>';
echo $arr{$full{"0"}}; //Outputs Array Value: mrs
echo '<br>';
?>
<?php
echo __LINE__; echo '<br>';
?>
<?php
//parse_str() Test: 8
//To output: Array Value.
$string = 'full[]=title&title=mrs&full[]=first_name&first_name=iris&full[]=surname&surname=alison';
parse_str($string,$arr);
echo $arr[$full][0]; //Outputs: Warning: Illegal offset type in ..
echo '<br>';
echo $arr[$full]['0']; //Outputs: Warning: Illegal offset type in ..
echo '<br>';
echo $arr[$full]["0"]; //Outputs: Warning: Illegal offset type in ..
echo '<br>';
echo $arr[$full]{0}; //Outputs: Warning: Illegal offset type in ..
echo '<br>';
echo $arr[$full]{'0'}; //Outputs: Warning: Illegal offset type in ..
echo '<br>';
echo $arr[$full]{"0"}; //Outputs: Warning: Illegal offset type in ..
echo '<br>';
?>
<?php
echo __LINE__; echo '<br>';
?>
<?php
//parse_str() Test: 9
//To output: Array Value.
$string = 'full[]=title&title=mrs&full[]=first_name&first_name=iris&full[]=surname&surname=alison';
parse_str($string,$arr);
echo $arr{$full}[0]; //Outputs: Warning: Illegal offset type in ..
echo '<br>';
echo $arr{$full}['0']; //Outputs: Warning: Illegal offset type in ..
echo '<br>';
echo $arr{$full}["0"]; //Outputs: Warning: Illegal offset type in ..
echo '<br>';
echo $arr{$full}{0}; //Outputs: Warning: Illegal offset type in ..
echo '<br>';
echo $arr{$full}{'0'}; //Outputs: Warning: Illegal offset type in ..
echo '<br>';
echo $arr{$full}{"0"}; //Outputs: Warning: Illegal offset type in ..
echo '<br>';
?>
<?php
echo __LINE__; echo '<br>';
?>
<?php
//parse_str() Test: 10
//To output: Array Value.
$string = 'full[]=title&title=mrs&full[]=first_name&first_name=iris&full[]=surname&surname=alison';
parse_str($string,$arr);
echo $arr['full[0]']; //Outputs: Notice: Undefined index: full[0] in ..
echo '<br>';
echo $arr['full['0']']; //Outputs: Notice: Undefined index: full['0'] in ..
echo '<br>';
echo $arr['full["0"]']; //Outputs: Notice: Undefined index: full["0"] in ..
echo '<br>';
echo $arr['full{0}']; //Outputs: Notice: Undefined index: full{0} in ..
echo '<br>';
echo $arr['full{'0'}']; //Outputs: Notice: Undefined index: full{'0'} in ..
echo '<br>';
echo $arr['full{"0"}']; //Outputs: Notice: Undefined index: full{"0"} in ..
echo '<br>';
?>
<?php
echo __LINE__; echo '<br>';
?>
<?php
//parse_str() Test: 11
//To output: Array Value.
$string = 'full[]=title&title=mrs&full[]=first_name&first_name=iris&full[]=surname&surname=alison';
parse_str($string,$arr);
echo $arr{'full[0]'}; //Outputs: Notice: Undefined index: full[0] in ..
echo '<br>';
echo $arr{'full['0']'}; //Outputs: Notice: Undefined index: full['0'] in ..
echo '<br>';
echo $arr{'full["0"]'}; //Outputs: Notice: Undefined index: full["0"] in ..
echo '<br>';
echo $arr{'full{0}'}; //Outputs: Notice: Undefined index: full{0} in ..
echo '<br>';
echo $arr{'full{'0'}'}; //Outputs: Notice: Undefined index: full{'0'} in ..
echo '<br>';
echo $arr{'full{"0"}'}; //Outputs: Notice: Undefined index: full{"0"} in ..
echo '<br>';
?>
<?php
echo __LINE__; echo '<br>';
?>
<?php
//parse_str() Test: 12
//To output: Array Value.
$string = 'full[]=title&title=mrs&full[]=first_name&first_name=iris&full[]=surname&surname=alison';
parse_str($string,$arr);
echo $arr['full'][0]; //Outputs: title
echo '<br>';
echo $arr['full']['0']; //Outputs: Outputs: title
echo '<br>';
echo $arr['full']["0"]; //Outputs: Outputs: title
echo '<br>';
echo $arr['full']{0}; //Outputs: Outputs: title
echo '<br>';
echo $arr['full']{'0'}; //Outputs: Outputs: title
echo '<br>';
echo $arr['full']{"0"}; //Outputs: Outputs: title
echo '<br>';
?>
<?php
echo __LINE__; echo '<br>';
?>
<?php
//parse_str() Test: 13
//To output: Array Value.
$string = 'full[]=title&title=mrs&full[]=first_name&first_name=iris&full[]=surname&surname=alison';
parse_str($string,$arr);
echo $arr{'full'}[0]; //Outputs: title
echo '<br>';
echo $arr{'full'}['0']; //Outputs: Outputs: title
echo '<br>';
echo $arr{'full'}["0"]; //Outputs: Outputs: title
echo '<br>';
echo $arr{'full'}{0}; //Outputs: Outputs: title
echo '<br>';
echo $arr{'full'}{'0'}; //Outputs: Outputs: title
echo '<br>';
echo $arr{'full'}{"0"}; //Outputs: Outputs: title
echo '<br>';
?>
<?php
echo __LINE__; echo '<br>';
?>
<?php
//parse_str() Test: 14
//To output: Array Value.
$string = 'full[]=title&title=mrs&full[]=first_name&first_name=iris&full[]=surname&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 ..
?>
<?php
echo __LINE__; echo '<br>';
?>
<?php
//parse_str() Test: 15
//To output: Array Value.
$string = 'full[]=title&title=mrs&full[]=first_name&first_name=iris&full[]=surname&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 ..
?>
<?php
echo __LINE__; echo '<br>';
?>
<?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&title=mrs&full[]=first_name&first_name=iris&full[]=surname&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.
?>
<?php
echo __LINE__; echo '<br>';
?>
[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]
0.1.9 — BETA 4.25