Jump to content

array help


dennismonsewicz

Recommended Posts

I always seem to get confused when I start working with an array where I want to append the results to the end of a string vs resetting the variable in a foreach statement.

 

$encodeArray = array(
			'claimID' => $_GET['barcode'],
			'deviceNumber' => $_GET['deviceNumber']
	);

foreach($encodedText as $k => $v) {
		$text = escapeshellarg($k . "=" . $v . '\n');
	}

	$text = '';

 

I want each key/value pair to show up in one string but all together... sorry if that is confusing. Also, how do I echo out a literal \n instead of the line break actually occurring?

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

Awesome that worked! but I have a weird problem happening...

 

$encArray = array(
				"claimID" => $_GET['barcode'],
				"dnumber" => $_GET['dnumber']
	);

$text = '';
foreach($encArray as $k => $v) {
	$text .= escapeshellarg("$k=$v" . '\\n');
}

echo $text;

 

the expected out put is claimID=12345\ndnumber=235342434

 

but I am getting:

claimID=213243131\n''dnumber=2563398716\n'

 

There is a double quote between the first var and the second... is there anyway to get rid of that?

Link to comment
https://forums.phpfreaks.com/topic/193407-array-help/#findComment-1018583
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.