dennismonsewicz Posted February 25, 2010 Share Posted February 25, 2010 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 More sharing options...
F00Baron Posted February 25, 2010 Share Posted February 25, 2010 How about this: $encodeArray = array( 'claimID' => $_GET['barcode'], 'deviceNumber' => $_GET['deviceNumber'] ); $text = ''; foreach($encodedText as $k => $v) { $text .= escapeshellarg($k . "=" . $v) . '\\n'; } Link to comment https://forums.phpfreaks.com/topic/193407-array-help/#findComment-1018279 Share on other sites More sharing options...
dennismonsewicz Posted February 26, 2010 Author Share Posted February 26, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.