adding 2 variables to a single array position
I am trying to add 2 variables which both happen to be checkboxes to an arra开发者_高级运维y that is part of a backend called SPIP.
The current array setup for the single checkbox looks like this:
$UpcomingEvent = 'is_upcoming_event';
$ThermometerEvent = 'is_thermometer_event';
$GLOBALS['champs_extra'] = array (
'articles' => array (
$nis => "checkbox|propre|New Inspirational Stories?",
$UpcomingEvent => "checkbox|propre|Is a Upcoming Event? (<em>present into Home page?</em>)",
$ThermometerEvent => "checkbox|propre|Add thermometer to event?",
'redirect_to_hyperlink' => "checkbox|propre|Redirect article to Hyperlink?"
)
);
$GLOBALS['champs_extra_proposes'] = Array (
'articles' => Array (
// tous : par defaut aucun champs extra sur les articles
'tous' => 'redirect_to_hyperlink',
// seul le champs extra "new_inspirational_stories" est propos� dans le secteur 42)
/**
* UpComming Events
*/
'44' => $UpcomingEvent,
'45' => $UpcomingEvent,
)
);
I want to add the ThermometerEvent variable to the array position 44 and 45 as well but can't figure out how to do it without overwriting the 44 or 45 position.
I tried putting it in another array like so but it did not work:
'45' => array($UpcomingEvent, $ThermometerEvent),
Any help is appreciated!
What "did not work"? Your '45' => array
looks to be fine. How were you attempting to access those values aftewards?
If you were to do
echo $GLOBALS['champs_extra_proposes']['articles']['44'];
you'd just get "Array", but doing
echo $GLOBALS['champs_extra_proposes']['articles']['44'][0];
should get you the value of $UpcomingEvent
You could have a fully two-dimensional array - see here:
http://www.webcheatsheet.com/PHP/multidimensional_arrays.php
Or use lists: http://php.net/list
<?php
$info = array('coffee', 'brown', 'caffeine');
// Listing all the variables
list($drink, $color, $power) = $info;
echo "$drink is $color and $power makes it special.\n";
// Listing some of them
list($drink, , $power) = $info;
echo "$drink has $power.\n";
// Or let's skip to only the third one
list( , , $power) = $info;
echo "I need $power!\n";
// list() doesn't work with strings
list($bar) = "abcde";
var_dump($bar); // NULL
?>
精彩评论