0

I am facing a problem using arrays. I want to loop an array withing a string.

Here is my Array

Array
(
    [0] => Product: 5 M Steel Pontoons: Quantity 10
    [1] => Product: 6.7 M Steel Pontoons: Quantity 15
)

I want to iterate this array between this string.

$message = "<p> Name = $name</p>
<p>Email = $email</p>
<p>Subject= $subject</p>"

So that the string would look like this

$message = "<p> Name = $name</p>

    <p>Email = $email</p>

<p>Product: 5 M Steel Pontoons: Quantity 10</>

<p>Product: 6.7 M Steel Pontoons: Quantity 15</p>   
    <p>Subject= $subject</p>"

Any one who can help???

2 Answers 2

2

You can try something like this :

$message = "<p> Name = $name</p>
<p>Email = $email</p>";

foreach((array) $yourArray as $key)
{
    $message .= "<p>".$key."</p>";
}

$message .= "<p>Subject= $subject</p>";
Sign up to request clarification or add additional context in comments.

Comments

0

As I understand you you can put shortecode in your $message like this:

$message = "<p> Name = $name</p>
<p>Email = $email</p>
{ADDITIONAL}
<p>Subject= $subject</p>"

then get that additional:

$additional = '';
foreach($array as $item) {
    $additional .= "<p>$item</p>";
}

than put it to message:

$message = str_replace('{ADDITIONAL}', $additional, $message);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.