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 9144873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:22:32+00:00 2026-06-17T10:22:32+00:00

For e.g. we have string $somestring = ’11;11;11;12;13′; and array $somearray = array( 11

  • 0

For e.g. we have string

$somestring = '11;11;11;12;13';

and array

    $somearray = array(
  11 => array(
    prop => array(0=>11),
    uid => 1,
  ),
  21 => array(
    prop => array(0=>12),
    uid => 2,
  ),
  32 => array(
    prop => array(0=>11),
    uid => 1,
  ),  
  34 => array(
    prop => array(0=>11),
    uid => 2,
  ),  
 35 => array(
    prop => array(0=>13),
    uid => 1,
  ),  
  36 => array(
    prop => array(0=>13),
    uid => 3,
  ),  
  37 => array(
    prop => array(0=>12),
    uid => 1,
  ),  
  38 => array(
    prop => array(0=>12),
    uid => 3,
  ),  
  39 => array(
    prop => array(0=>12),
    uid => 1,
  ),
);

How to get from $somearray [uid] on condition that value of [prop] is equal same value in $somestring and output it by filled rows like this:

row1:11(uid:1);11(uid:1);11(uid:2);12(uid:2);13(uid:1)
row2:11(uid:);11(uid:);11(uid:);12(uid:1);13(uid:3)
row3:11(uid:);11(uid:);11(uid:);12(uid:3);13(uid:)
row4:11(uid:);11(uid:);11(uid:);12(uid:1);13(uid:)

I found a bit reletive solution here http://eval.in/6816 but it is not dealing with repeated values

  • 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-06-17T10:22:33+00:00Added an answer on June 17, 2026 at 10:22 am

    Just copy it and execute,

    <?php
    error_reporting(0);
    $somestring = '11;11;11;12;13';
    
    $somearray = array(
      11 => array(
        prop => array(0=>11),
        uid => 1,
      ),
      21 => array(
        prop => array(0=>12),
        uid => 2,
      ),
      32 => array(
        prop => array(0=>11),
        uid => 1,
      ),  
      34 => array(
        prop => array(0=>11),
        uid => 2,
      ),  
     35 => array(
        prop => array(0=>13),
        uid => 1,
      ),  
      36 => array(
        prop => array(0=>13),
        uid => 3,
      ),  
      37 => array(
        prop => array(0=>12),
        uid => 1,
      ),  
      38 => array(
        prop => array(0=>12),
        uid => 3,
      ),  
      39 => array(
        prop => array(0=>12),
        uid => 1,
      ),
    );
    
    $sme_array    = explode(";",$somestring);
    $somestrarray = array_unique($sme_array);
    $res          = array();
    foreach($somearray as $key=>$val){
    
        foreach($somestrarray as $value){
            if($val['prop'][0] == $value){
               $res[$value][]   = $val['uid'];
            }       
        }
    }
    
    $cnt_values  = array_count_values($somestrarray);
    
    $num_loop    = 1;
    foreach($cnt_values as $key=>$val){
      $num_loop  = (count($res[$key])/$val) > $num_loop?(count($res[$key])/$val):$num_loop;
    }
    
    for($i=0; $i<$num_loop; $i++){
        echo "row".($i+1).":";
        foreach($sme_array as $vals){
          if(array_key_exists($vals,$res)){
          echo $vals."(uid:".$res[$vals][0].");";
          array_shift($res[$vals]);
          }
        }
        echo "<br>";
    }
    
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string that is output as a date: #{bean.someString} I want to
I have local table and string that must be populated from its values: DECLARE
I have a hashset in C# that I'm removing from if a condition is
I noticed myself constantly typing: someVar = getResources().getString(R.string.someString); I have several XML files that
I have this string: var someString = 23/03/2012; and want to replace all the
HI, I have some string from XML file, and I I want to replace
I have a static util class that does some string manipulation on a bit
I have the following for loop: for(String s : someString.split(\\s+)){ //do something } Does
I have a string that has data separated by a pipe character ( |
I have a string, and I need to get its first character. var x

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.