Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.