Note that there are some explanatory texts on larger screens.

plurals
  1. POComplex String replace
    primarykey
    data
    text
    <p>Okay im totally stuck on this, it should be pretty simple.</p> <p>I have two arrays:</p> <pre><code>array(2) { [0]=&gt; array(7) { ["id"]=&gt; string(1) "4" ["name"]=&gt; string(9) "Page name" ["content"]=&gt; string(133) "&lt;div class="content col-lg-12"&gt;[Jumbo]&lt;/div&gt;&lt;div class="content col-lg-12"&gt;[Jumbo]&lt;/div&gt;&lt;div class="content col-lg-12"&gt;[Footer]&lt;/div&gt;" ["container"]=&gt; string(1) "0" ["background"]=&gt; string(7) "#ff7676" ["homepage"]=&gt; string(1) "1" ["active"]=&gt; string(1) "1" } [1]=&gt; array(7) { ["id"]=&gt; string(1) "7" ["name"]=&gt; string(8) "Layout 1" ["content"]=&gt; string(119) "&lt;div class="content col-lg-12"&gt;[Header]&lt;/div&gt;&lt;div class="content col-lg-12"&gt;&lt;/div&gt;&lt;div class="content col-lg-12"&gt;&lt;/div&gt;" ["container"]=&gt; string(1) "1" ["background"]=&gt; string(7) "#ff7676" ["homepage"]=&gt; string(1) "1" ["active"]=&gt; string(1) "1" } } </code></pre> <p>and:</p> <pre><code>array(2) { [0]=&gt; array(9) { ["id"]=&gt; string(1) "8" ["name"]=&gt; string(5) "Jumbo" ["headCSS"]=&gt; string(0) "" ["classes"]=&gt; string(39) "jumbotron module col-lg-6 round-corners" ["inlineCSS"]=&gt; string(144) "background: none repeat scroll 0% 0% rgb(229, 255, 135); border-width: 3px; border-style: solid; border-color: rgb(45, 152, 255); padding: 10px;" ["element"]=&gt; string(247) " &lt;div style="background: none repeat scroll 0% 0% rgb(229, 255, 135); border-width: 3px; border-style: solid; border-color: rgb(45, 152, 255); padding: 10px;" class="jumbotron module col-lg-6 round-corners"&gt;Example&lt;/div&gt; " ["type"]=&gt; string(6) "header" ["size"]=&gt; string(1) "6" ["content"]=&gt; string(7) "Example" } [1]=&gt; array(9) { ["id"]=&gt; string(2) "12" ["name"]=&gt; string(6) "Footer" ["headCSS"]=&gt; string(0) "" ["classes"]=&gt; string(30) "module round-corners col-lg-10" ["inlineCSS"]=&gt; string(64) "background: none repeat scroll 0% 0% transparent; padding: 10px;" ["element"]=&gt; string(143) "&lt;footer style="background: none repeat scroll 0% 0% transparent; padding: 10px;" class="module round-corners col-lg-10"&gt;&lt;p&gt;Raaaa!&lt;/p&gt; &lt;/footer&gt;" ["type"]=&gt; string(6) "footer" ["size"]=&gt; string(2) "10" ["content"]=&gt; string(14) "&lt;p&gt;Raaaa!&lt;/p&gt; " } } </code></pre> <p>Basically I want to replace the occurances of [xxx] in the first array[content] with the second array[element] that matches the array[name]. Hope that makes sense (?!)</p> <p>So far I have tried this:</p> <pre><code>foreach($array1 as $layout) { foreach($array2 as $module) { $needle = "[" . trim($module['name']) . "]"; $pages[$layout['name']] = str_replace($needle, $module['element'], $layout['content']); }; }; </code></pre> <p>However that only seems to replace the content matched in the first array2 element and not all of them.</p> <p>Any idea whats wrong?</p> <p>As a side note, iv done some reading and think this might be easier with strtr() but im not sure if thats possible with my data. any advise on this would be great!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload