Problem with displaying HTML content after in_array [closed]

Notice that there are no echo statements, so nothing will be output. You need to echo the result, or nothing will be sent to the browser.

If it was just a basic loop (without a blue container) I could style the posts with nth-child formula, but I need to place this container in between the groups of posts… and I was hoping that above code would help me to achieve this, but it doesn’t place this additional container 🙂

It doesn’t place the container because you never echo the result. Instead it’s silently discarded because nothing was done with it.

E.g.

$colour="red";
// this will not do anything
( $colour === 'red') ? "it's red" : "it is not red";

// but this will:
echo ($colour === 'red') ? "it's red" : "it is not red";

Some tips going forward:

  • In general, avoid ternary operators, and keep in mind that they simply act as a value replacement, you still have to do something with the result.
  • Try to stick to the () ? : version as it makes it clearer which bit is the test as it’s in brackets
  • Keep in mind that using nested or adjacent ternary operators can get confusing very quickly, e.g. what is the value of: $test = true ? true ? "a" : "b" : "c", very confusing.
  • In other languages, the order is reversed, so instead of condition ? true : false it’s condition ? false: true, which gets confusing
  • When counting you can probably get away with CSS grids/flex/nth-child selectors