R
R
redfox422015-09-11 15:32:22
PHP
redfox42, 2015-09-11 15:32:22

How to insert the result of an if?

I'm trying to make the correct yml file for Yandex. They had complaints about the availability of goods. Since the programmer is not currently on the project, you have to figure it out yourself.
There is such a design:

echo '<offers>';
    foreach($items_res as $item){
        echo '<offer id="'.$item['id'].'" available="<b>XXX</b>">';

Here is the condition (if the availability of the product is greater than 0, then display "true", if it is less than or equal to 0, then you need to display "false") must be put in place of XXX :

is the tv parameter that needs to be output as well.
how to do it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
IPv4, 2015-09-11
@IPv4

echo '<offers>';
    foreach($items_res as $item){
        echo '<offer id="'.$item['id'].'" available="<b>' . if($item['num'] > 0) {echo 'true';} else {echo 'false';} . '</b>">';

Not?

A
Alexey Kolesnikov, 2015-09-11
@alexhit

Everything is simple, but you need to know the name of the field in the array that stores the count (if it is in your array at all, it is not clear from this piece of code). If you don't know, you can check like this:

foreach($items_res as $item){
   echo '<pre>';
   print_r($item);
   echo '</pre>';
   exit();
}

See the structure of your array, if it contains a quantity, then we will use the name of the desired field for comparison and insertion:
foreach($items_res as $item){
   if ($item['kolichestvo']>0) echo '<offer id="'.$item['id'].'" available="true">';
   else echo '<offer id="'.$item['id'].'" available="false">';

G
Gluck Virtualen, 2015-09-12
@gluck59

Show the $item structure.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question