Heroes, read the strings in PHP and ask for help.

Source: Internet
Author: User
$str = " Shei
Bidandan
Machali
Li Xin
Li Ping ";
There is a string of strings that are processed by PHP to get a new array (name, count value);
For example, generate $ars =array (' 0 ' = ' Shei ', ' 0 ' = ' Bidandan ', ' 0 ' = ' Machali ', ' 0 ' + ' li Xin ', ' 1 ' = ' li ping ');

Please help the heroes, thank you.


Reply to discussion (solution)

$str = "
 
  
   
  Shei
 
  
 
  
   
  Bidandan
 
  
 
  
   
  Machali
 
  
 
  
   
  Li Xin
 
  
 Li 
  
   
  ping
 
   ";p reg_match_all ("/
 
  
   
  (. *?) <\/v:note>/", $str, $matches); $newArr = Array_combine ($matches [2], $matches [1]); Var_dump ($NEWARR);? >
 
  

It is not possible to have the same key value in the PHP array, so the key value can only be guaranteed by name.

It's impossible to generate the kind you want. The same key cannot be present at the same time. The latter will cover the former.

Only Array (' 0 ' = ' Shei ', ' 1 ' = ' Bidandan ', ' 2 ' = ' Machali ', ' 3 ' + ' Li Xin ', ' 4 ' = ' li ping '); Like this.

Your count can't be a key.

$str = "
 
  
   
  Shei
 
  
 
  
   
  Bidandan
 
  
 
  
   
  Machali
 
  
 
  
   
  Li Xin
 
  
 Li 
  
   
  ping
 
   ";p reg_match_all ("/
 
  
   
  (. *?) <\/v:note>/", $str, $matches); $newArr = Array_combine ($matches [2], $matches [1]); Var_dump ($NEWARR);? >
 
  

It is not possible to have the same key value in a PHP array, so you can only use the name to make a key value to ensure that the only result is a string array (5) {
["Shei"]=>
String (1) "0"
["Bidandan"]=>
String (1) "0"
["Machali"]=>
String (1) "0"
["Li Xin"]=>
String (1) "0"
["Li Ping"]=>
String (1) "1"
}
Can this string be removed?

It's impossible to generate the kind you want. The same key cannot be present at the same time. The latter will cover the former.

Only Array (' 0 ' = ' Shei ', ' 1 ' = ' Bidandan ', ' 2 ' = ' Machali ', ' 3 ' + ' Li Xin ', ' 4 ' = ' li ping '); Like this.

Your count can't do the key, I just have to sort the header by the value inside count


The string where there is no string is the output from anywhere else.


The string where there is no string is the output from anywhere else. Thank you for your points.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.