douwen1549 2017-05-09 15:34 采纳率: 100%
浏览 71

使用不同的preg_match_all将唯一数组应用于字符串数组

i've a logical problem that i don't know how to solve, i'm a lot confused about it.

I've an array composed in this way:

titoli[
    1 => 'NFL'
    2 => 'Johnny Depp'
    3 => 'Institute of Technology'
    4 => 'Another text'
]

Now, I need to apply different regex to that array, how can i do that and have a single final array?

For now i've written this:

for($i=0;$i<sizeof($titoli);$i++)
{
    if(str_word_count($titoli[$i]) > preg_match_all('/([A-Z][a-zA-Z0-9-]*)([\s][A-Z][a-zA-Z0-9-]*)+/', $titoli[$i]))
{
    preg_match('/([A-Z][a-zA-Z0-9-]*)([\s][A-Z][a-zA-Z0-9-]*)+/', $titoli[$i], $result[$i]);
    $i++;
}
if(str_word_count($my_array[$i]) > preg_match_all('/^[A-Z][a-z]* [a-z]+ [A-Z][a-z]*$/', $titoli[$x]) && preg_match_all('/^[A-Z][a-z]* [a-z]+ [A-Z][a-z]*$/', $titoli[$i]) > 0) //controlla che nel titolo non siano state messe tutte le parole con l'iniziale maiuscola
{
    preg_match('/^[A-Z][a-z]* [a-z]+ [A-Z][a-z]*$/', $titoli[$x], $result_b[$y], PREG_PATTERN_ORDER);
    $y++;
}
}
  • 写回答

2条回答 默认 最新

  • donglian1523 2017-05-09 15:37
    关注

    Well, you could merge the arrays then extract the unique values:

    $merged = array_merge($array1, $array2, $array3);
    
    $unique = array_unique($merged);
    

    Where $array1, $array2 and $array3 are the results of the preg_match_all functions.

    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源