Please help me out, i came across this script in my project. Is this html array or php array ?
<input type="hidden" name="newsletter['.$var["id"].'][someid]" value="'.$var['id'].'" />
Please help me out, i came across this script in my project. Is this html array or php array ?
<input type="hidden" name="newsletter['.$var["id"].'][someid]" value="'.$var['id'].'" />
This is a combination between the two. For example, the following:
<input type='text' name='arr[foo]' value='fooValue' />
<input type='text' name='arr[bar]' value='barValue' />
When submitted, this will be read by PHP into an array called arr, looking like this:
$_POST['arr'] (
'foo' => 'fooValue',
'bar' => 'barValue'
)
This makes being able to pass arrays to your PHP script a lot easier, either through the generating PHP, or through javascript, or similar.
The specific example you have is using a PHP array to generate some HTML that can then be read as an array in the next PHP script, but HTML itself does nto have the concept of an array.
<a href="<?php echo $url?>"><?php echo $url_title?></a>It looks like part of a PHP script. I imagine the rest looks something like this:
$html = '<input type="hidden" name="newsletter[' . $var["id"] .
'][someid]" value="' . $var['id'] . '" />'
When evaluated it should produce something like the following HTML string:
<input type="hidden" name="newsletter[123][someid]" value="123" />
Lets break this down..
<input type="hidden" name="newsletter['.$var["id"].'][someid]" value="'.$var['id'].'" />
Without the PHP...
<input type="hidden" name="newsletter[removed][someid]" value="removed" />
Is an HTML input field set up to post as an array. If you called $_POST['newsletter'] it would return an array. So this part is an HTML array.
The $var["id"] PHP variable is an array. It is calling the "id" index of the $var associative array.
So it is both an HTML array and a PHP array. If you were to execute this field and analyze the post data in PHP using the following snippet:
if (isset($_POST['newsletter']))
die(print_r($_POST));
$var = array('id' => 2); // assume $var['id'] = 2
echo "<form method='post'>";
echo '<input type="hidden" name="newsletter['.$var["id"].'][someid]" value="'.$var['id'].'" />';
echo "<input type='submit' />";
echo "</form>";
Upon submitting you would see the following array in $_POST['newsletter']
Array
(
[newsletter] => Array
(
[2] => Array
(
[someid] => 2
)
)
)
HTML doesn't have a concept of an array.
All inputs will be part of the elements collection of the HTMLFormElement in DOM (which is accessible via client side JS).
The name of the input will, when submitted to a PHP script, cause PHP to expand it into a value assigned to a key in an associative array assigned to a key in another associative array assigned to the newsletter key in the $_REQUEST and either the $_GET or $_POST superglobal arrays.