ここに私の簡単なソースコードがあります
<?php
$index1 = 1;
$index2 = "<span style='color:red'>".$index1."</span>";
$index3 = intval("<span style='color:red'>".$index1."</span>");
$array = array(0=>"Apple", 1=>"Orange");
print_r($array[$index1]);//output will be "Orange"
print_r($array[$index3]);//output "Apple", this should be "Orange"
print_r($array[$index2]);//Notice: Undefined index: 1
?>
出力プログラムに色付きのインデックスを取得する必要があります。intval
を追加して、is_int
整数に変換しようとしました。しかし、何も起こりませんでした。配列の正しい色付きインデックスを取得するにはどうすればよいですか?