0

I have a nested json, and i used the following code to extract, and it lists all the data from it, however i want to skip a particular data

Say the list is this

$ip = Array ( [0] => 1.1.1.1 [1] => 1.1.1.2 [2] => 1.1.1.3 [3] => 1.1.1.4 [4] => 1.1.1.5 )

I want to list all the IPs in a line and i can achieve that with following code in php

foreach ($ip as $character) {
    $state .= "<div 'col-sm-7 text-left'>$character<br></div>";;
    }

However say i want to skip 1.1.1.3, how can i do that?

I want the output to be like

1.1.1.1
1.1.1.2
1.1.1.4
1.1.1.5

1 Answer 1

1
foreach ($ip as $character) {
    if ('1.1.1.3' !== $character) {
        $state .= "<div 'col-sm-7 text-left'>$character<br></div>";
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

That works, thanks. I have 1 more query, can you help me with it? This is a code i made of your suggestion - 3v4l.org/Bh6JK however i want to move the first line (extra ips) within the foreach function, but when i do it, it repeats everytime for each IP, anyway to prevent it?
That's why how foreach works - it repeats action every time. What's the problem with setting this header outside foreach?
That's not php problem. that's markup bug - css + html. Open developers console and try to find out why this happens and what need to be fixed.

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.