1

私はこの文字列を持っています:

[{"position":"1d","number":10,"nb_plot1":12,"max_actions":3}
{"position":"2d","number":7,"nb_plot1":15,"max_actions":30}
{"position":"3d","number":100,"nb_plot1":2,"max_actions":5}]

そして、次のような異なる形式の2つの異なる文字列を取得する必要があります:

数字の場合:

[10,7,100]

ポジションの場合:

['1d','2d','3d']

不要な弦をカットします。

ノブですみません。

4

1 に答える 1

2

json_decodeを使用して配列内の文字列をデコードします。

この配列を繰り返し処理し、数値と位置の新しい配列を作成します。

配列をエンコードします。

コード内:

$arr = json_decode($string);

$numbers = array();
$positions = array();

foreach($arr as $a) 
{
    $numbers[] = (int)$a->number;
    $positions[] = $a->position;
}

$number_string = json_encode($numbers);
$position_string = json_encode($positions);
于 2012-04-25T19:57:43.350 に答える