S. A. Malik
S. A. Malik

Reputation: 3655

Select elements other then a specific one form Xml Object

I am parsing the array given below. Looping through td using foreach. Now i want to select the value other than [@attributes]. I cannot use a or p specifically as they change through out the objects.

How can i achieve this?

[0] => SimpleXMLElement Object
    (
        [th] => SimpleXMLElement Object
            (
                [@attributes] => Array
                    (
                        [rowspan] => 2
                        [scope] => row
                    )

                [p] => Memory
            )

        [td] => Array
            (
                [0] => SimpleXMLElement Object
                    (
                        [@attributes] => Array
                            (
                                [class] => ttl
                            )

                        [a] => Card slot
                    )

                [1] => SimpleXMLElement Object
                    (
                        [@attributes] => Array
                            (
                                [class] => nfo
                            )

                        [p] => No
                    )

            )

    )

Want the solution to work in php.

Upvotes: 0

Views: 32

Answers (1)

Smile
Smile

Reputation: 2758

Try below one

<?php
foreach($td as $element)
{
    foreach($element as $key => $value)
    {
        if(!preg_match("/@/", $key) && !is_array($value))
            echo $element[$key];
    }
}
?>

Upvotes: 2

Related Questions