Jump to content

Help With An Array


MainStWebGuy

Recommended Posts

Hello everyone,

 

I am trying to get values from some input forms and put them into an array but I'm not getting it. I would like to store some vehicle information that a user enters in a simple for in an array so i can use it in my app, but i think i'm screwing up the syntax... what am i doing wrong?

	$unit1 = array('Number' => $_POST['unit1'], 'Year' => $_POST['year1'], 'Make' => $_POST['make1'], 'Model' => $_POST['model1'], 'Glass' => $_POST['unit1Glass']);

 

any insight, advice, hysterical comments encouraged and appreciated :)

 

Link to comment
https://forums.phpfreaks.com/topic/246990-help-with-an-array/
Share on other sites

Sure thing:

 

<?php
if(isset($_POST['sendRequest']))
{
	$fleet = $_POST['fleet'];
	$contact = $_POST['contact'];
	$time = $_POST['start_month']." ".$_POST['start_day'].". ".$_POST['start_hour'].":".$_POST['start_minute']." ".$_POST['amPm'];
	$unit1 = array('Number' => $_POST['unit1'], 'Year' => $_POST['year1'], 'Make' => $_POST['make1'], 'Model' => $_POST['model1'], 'Glass' => $_POST['unit1Glass']);
        $unit2 = array('Number' => $_POST['unit2'], 'Year' => $_POST['year2'], 'Make' => $_POST['make2'], 'Model' => $_POST['model2'], 'Glass' => $_POST['unit2Glass']);
         
	$notes = $_POST['notes'];
	$msg = "Fleet: $fleet. Contact: $contact\n$unit1['Year'] $unit1['Make'] $unit1['Model'] $unit1['Glass']\n";
		if(isset($_POST['unit2']) && $_POST['unit2'] != '')
		{
			$msg .= "$unit2['Year'] $unit2['Make'] $unit2['Model'] $unit2['Glass']\n";
		}

 

if this isn't enough code, i'd be happy to show whatever else might help. Thanks again!

Link to comment
https://forums.phpfreaks.com/topic/246990-help-with-an-array/#findComment-1268476
Share on other sites

Quoted keys don't work in simple syntax. Use curly braces (complex syntax) for those.

 

www.php.net/manual/en/language.types.string.php#language.types.string.parsing

 

<?php
$msg = "Fleet: $fleet. Contact: $contact\n{$unit1['Year']} {$unit1['Make']} {$unit1['Model']} {$unit1['Glass']}\n";
?>

Link to comment
https://forums.phpfreaks.com/topic/246990-help-with-an-array/#findComment-1268488
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.