我有一個像如何從字符串獲得子字符串在Php
$totalValues ="4565:4,4566:5,4567:6";
現在字符串我想':'
昏迷分離後僅值,即我想串像$SubValues = "4,5,6"
感謝
我有一個像如何從字符串獲得子字符串在Php
$totalValues ="4565:4,4566:5,4567:6";
現在字符串我想':'
昏迷分離後僅值,即我想串像$SubValues = "4,5,6"
感謝
$totalValues ="4565:4,4566:5,4567:6";
echo implode(',',array_map(function($val){
$val = explode(':',$val);
return $val[1];
},explode(',',$totalValues)));
試試這個代碼,它正在
<?php
$str="4565:4,4566:5,4567:6";;
$data =explode(",", $str);
echo '<pre>';
print_r($data);
$newstring="";
foreach ($data as $key => $value) {
preg_match('/:(.*)/',$value,$matches);
$newstring.=$matches[1].",";
}
echo rtrim($newstring,",");
我已經更新了我的代碼,請檢查一下
<?php
$str="4565:4,4566:5,4567:6";
$data1=explode(",", $str);
$newstring1="";
foreach ($data1 as $key1 => $value) {
preg_match('/(.*?):/',$value,$matches);
$newstring1.=$matches[1].",";
}
echo rtrim($newstring1,",");
謝謝@Sharma Vikram,現在我想要「4565,4566,4567」字符串,請幫助我 – Shekkar
請檢查它 –
你可能想這樣說:
$totalValues ="4565:4,4566:5,4567:6";
$temp = explode(':', $totalValues);
$subValues = $temp[1][0];
$x = count($temp);
for ($i = 2; $i < $x; $i++) {
$subValues .= ',' . $temp[$i][0];
}
echo $subValues;
爲什麼人們賦予下坡實時開發問題 – Shekkar
您的問題有沒有試圖嘗試的跡象也沒有研究工作 – Andrew