-1

Here is part of something im trying to do, Where ive got the 2nd $course_item .= i want to add a word here so its actually like:

cerealchoices or toastchoices etc etc

How can i add the word choices to the end of the $course_item variable?

This is to loop through all the text boxes.

$course_menuname = $row['course_menuname']; #E.G breakfast_cereal, breakfast_toast
$course_item = $row['course_jsname']; #E.G cereal, toast, jacketpotato
if(!empty($course_menuname)) {
   foreach($course_menuname as $course_item) {
    $course_item = trim($course_item);
    if(!empty($course_item)) {
      $course_item .= "$course_item;";
    }
   }
 }

This is what i want it to look like:

$course_menuname = $row['course_menuname']; #E.G breakfast_cereal, breakfast_toast
$course_item = $row['course_jsname']; #E.G cereal, toast, jacketpotato
if(!empty($_POST['breakfast_cereal'])) {
   foreach($_POST['breakfast_cereal'] as $cereal) {
    $cereal= trim($cereal);
    if(!empty($cereal)) {
      $cerealchoices .= "$cereal;";
    }
   }
 }

Where it says cerealchoices, in the first one the variable $course_item has the word cereal i want to add the world choices to the end of it?

4

2 回答 2

2
$course_item = "{$row['course_jsname']}choices";

应该做你需要的。请注意,花括号实际上并没有打印出来,它们只是告诉 PHP 将所有包含的文本视为一个变量。

于 2013-10-29T16:06:51.077 回答
2

这应该可以帮助您实现目标:)

$course_item = $row['course_jsname']."choices";

尽管 Philip Pryce 有一个更优雅的解决方案 :)

阅读PHP 手册中的更多内容

于 2013-10-29T16:08:27.113 回答