Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6228293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:21:52+00:00 2026-05-24T09:21:52+00:00

test.xml <?xml version=1.0 encoding=UTF-8?> <items> <item> <id>1</id> <num>10</num> <text>text1</text> </item> <item> <id>2</id> <num>8</num> <text>text2</text>

  • 0

test.xml

<?xml version="1.0" encoding="UTF-8"?>
<items>
<item>
  <id>1</id>
  <num>10</num>
  <text>text1</text>
</item>
<item>
  <id>2</id>
  <num>8</num>
  <text>text2</text>
</item>
<item>
  <id>3</id>
  <num>17</num>
  <text>text3</text>
</item>
<item>
  <id>4</id>
  <num>5</num>
  <text>text4</text>
</item>
<item>
  <id>5</id>
  <num>9</num>
  <text>text5</text>
</item>
</items>

How to do if <num> >=9 , shuffle the items and print the <text>?

$xml = simplexml_load_file('test.xml');
foreach ($xml->item as $key=>$data){
    if(($data->num)>=9){
        ... 
    }
}

need out put like:

text1 text3 text5 OR text1 text5 text3 OR text3 text1 text5 … //text1 text3 text5 is not smaller than 9, then print them and make their position radom

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:21:53+00:00Added an answer on May 24, 2026 at 9:21 am

    When they pass, add them to an (associative) array.

    After the foreach loop, shuffle($array) will shuffle them and then print them as usual (echo $array[0].$array[1].$array[2]).

    Is this what you were looking for?

    EDIT:

    $passedArray = array();
    
    $xml = simplexml_load_file('test.xml');
    foreach ($xml->item as $key=>$data){
        if(($data->num)>=9){
            $passedArray[] = $data->text;
        }
    }
    
    shuffle($passedArray);
    

    And then:

    foreach ($passedArray as $value) {
        echo $value.' ';
    }
    

    This will leave a trailing space. This is better:

    $string = '';
    
    foreach ($passedArray as $value) {
        $string += $value.' ';
    }
    
    echo substr($string, 0, strlen($string)-1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml document with the following structure: <?xml version=1.0 encoding=UTF-8?> <items> <item>
I'm editing XML element with the following XML: <?xml version=1.0 encoding=utf-8?> <!--Test XML with
This is my XML: <?xml version=1.0 encoding=UTF-8?> <?xml-stylesheet href=test_2.xsl type=text/xsl?> <doc xmlns=http://www.foo.org> <div> <title>Mr.
I'm reading an XML file that looks like this: <?xml version=1.0 encoding=utf-8?> <VehicleList> <Vehicle>
I have xml file whose structure is defined with following xsd: <?xml version=1.0 encoding=utf-8?>
I have an XML file formatted like this: <?xml version=1.0 encoding=utf-8?> <Snippets> <Snippet name=abc>
i have following xml <?xml version=1.0 encoding=UTF-8 ?> <Users> <User> <ID>SMSUser(63)</ID> <Email>a@example.com</Email> </User> <User>
When I feed a utf-8 encoded xml to an ExpatParser instance: def test(filename): parser
I'm trying to disable log output from all external libraries in logback-test.xml. Somehow it
I have following test class @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {/services-test-config.xml}) public class MySericeTest { @Autowired

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.