0

php で for ループを実行しました。次の出力が得られました...最初の値を他の配列に保存し、2 番目の値を他の配列に保存しようとしています...誰かがそれを行うようにガイドしてください!

または、2次元配列に格納する方法

配列
(
    [0] => 44
    [1] => 810
)
配列
(
    [0] => 0
    [1] => 280
)
配列
(
    [0] => 73
    [1] => 279
)
配列
(
    [0] => 0
    [1] => 278
)
配列
(
    [0] => 0
    [1] => 277
)
配列
(
    [0] => 0
    [1] => 276
)
配列
(
    [0] => 87
    [1] => 840
)
配列
(
    [0] => 0
    [1] => 275
)
配列
(
    [0] => 0
    [1] => 274
)
配列
(
    [0] => 0
    [1] => 273
)
配列
(
    [0] => 6
    [1] => 271
)
配列
(
    [0] => 0
    [1] => 272
)
配列
(
    [0] => 0
    [1] => 269
)
配列
(
    [0] => 3
    [1] => 267
)
配列
(
    [0] => 0
    [1] => 268
)
配列
(
    [0] => 3
    [1] => 259
)
配列
(
    [0] => 108
    [1] => 124
)
配列
(
    [0] => 82
    [1] => 239
)
配列
(
    [0] => 221
    [1] => 238
)
配列
(
    [0] => 30
    [1] => 160
)
配列
(
    [0] => 3
    [1] => 161
)
配列
(
    [0] => 65
    [1] => 168
)
配列
(
    [0] => 73
    [1] => 169
)
配列
(
    [0] => 0
    [1] => 170
)
配列
(
    [0] => 0
    [1] => 248
)
配列
(
    [0] => 192
    [1] => 226
)
配列
(
    [0] => 209
    [1] => 222
)
配列
(
    [0] => 80
    [1] => 223
)
配列
(
    [0] => 182
    [1] => 273
)
配列
(
    [0] => 79
    [1] => 183
)
配列
(
    [0] => 73
    [1] => 184
)
配列
(
    [0] => 73
    [1] => 185
)
配列
(
    [0] => 6
    [1] => 186
)
配列
(
    [0] => 73
    [1] => 187
)
配列
(
    [0] => 0
    [1] => 188
)
配列
(
    [0] => 48
    [1] => 270
)
配列
(
    [0] => 138
    [1] => 190
)
配列
(
    [0] => 191
    [1] => 370
)
配列
(
    [0] => 152
    [1] => 192
)
配列
(
    [0] => 12
    [1] => 200
)
配列
(
    [0] => 200
    [1] => 210
)
配列
(
    [0] => 0
    [1] => 213
)
配列
(
    [0] => 21
    [1] => 212
)
配列
(
    [0] => 124
    [1] => 214
)
配列
(
    [0] => 0
    [1] => 215
)
配列
(
    [0] => 0
    [1] => 216
)
配列
(
    [0] => 133
    [1] => 217
)
配列
(
    [0] => 6
    [1] => 260
)
配列
(
    [0] => 73
    [1] => 285
)
配列
(
    [0] => 73
    [1] => 284
)
配列
(
    [0] => 0
    [1] => 283
)
配列
(
    [0] => 73
    [1] => 286
)
配列
(
    [0] => 73
    [1] => 287
)
配列
(
    [0] => 0
    [1] => 288
)
配列
(
    [0] => 73
    [1] => 289
)
配列
(
    [0] => 0
    [1] => 290
)
配列
(
    [0] => 76
    [1] => 291
)
配列
(
    [0] => 76
    [1] => 292
)
配列
(
    [0] => 0
    [1] => 293
)
配列
(
    [0] => 0
    [1] => 294
)
配列
(
    [0] => 0
    [1] => 295
)
配列
(
    [0] => 0
    [1] => 296
)
配列
(
    [0] => 0
    [1] => 297
)
配列
(
    [0] => 3
    [1] => 298
)
配列
(
    [0] => 0
    [1] => 299
)
配列
(
    [0] => 0
    [1] => 300
)
配列
(
    [0] => 3
    [1] => 301
)
4

2 に答える 2

4

使用できます

$a = $b = array();
foreach ( $array as $list ) {
    list($a[], $b[]) = $list;
}

ライブデモを見る

于 2012-10-20T13:34:43.130 に答える
2

このようなもの?

$first = array();
$second = array();
$sourceArray = //this is what you are looping over. 
//Your loop
foreach($sourceArray as $array) {
    $first[] = $array[0];
    $second[] = $array[1];
}
于 2012-10-20T13:33:33.887 に答える