#b-navbar { height:0px; display:none; visibility:hidden; }

ページ

2011年6月16日木曜日

PHP:配列操作:high番目をlow番目に繰り上げる


$aaa = array();
$aaa[0]["color"] = "red";
$aaa[0]["image"] = "apple";

$aaa[1]["color"] = "blue";
$aaa[1]["image"] = "nasubi";

$aaa[2]["color"] = "green";
$aaa[2]["image"] = "hourensou";

$aaa[3]["color"] = "yellow";
$aaa[3]["image"] = "lemon";



print_r( $aaa ) ;
print "<br />";

$aaa = KuriageArray ( $aaa , 3,1);

print_r( $aaa ) ;
print "<br />";



function KuriageArray( $ary_input, $high, $low ) {
//high番目をlowに移動して、それ以下の順番を繰り下げる
//(降格・繰り下げはできない。すなわちhigh>=low)

$num_input = count ( $ary_input );
$ary_output = array();

for ($ixx = 0; $ixx < $low ; $ixx++) {
$ary_output [$ixx] = $ary_input [$ixx] ;
}

$ary_output [$low] = $ary_input [$high] ;

for ($ixx = $low + 1 ; $ixx < $high+1 ; $ixx++) {
$ary_output [$ixx] = $ary_input [$ixx - 1] ;
}
for ($ixx = $high + 1 ; $ixx < $num_input ; $ixx++) {
$ary_output [$ixx] = $ary_input [$ixx ] ;
}

return $ary_output;

}



↓出力---------------------------
Array
(
[0] => Array
(
[color] => red
[image] => apple
)

[1] => Array
(
[color] => blue
[image] => nasubi
)

[2] => Array
(
[color] => green
[image] => hourensou
)

[3] => Array
(
[color] => yellow
[image] => lemon
)

)

Array
(
[0] => Array
(
[color] => red
[image] => apple
)

[1] => Array
(
[color] => yellow
[image] => lemon
)

[2] => Array
(
[color] => blue
[image] => nasubi
)

[3] => Array
(
[color] => green
[image] => hourensou
)

)


昇格、入替が、順位繰り下げができている。

PHP:配列操作

転置する(行と列を入替える):
http://aki.adam.ne.jp/bbs/question/detail.php?rt=2751&id=2751

<?
$ary1 = array(1,2,3,4,5);
$ary2 = array("a","b","c","d","e");
$ary3 = array("あ","い","う","え","お");
$ary[] = $ary1;
$ary[] = $ary2;
$ary[] = $ary3;
print_r($ary);
foreach($ary AS $key => $item){
foreach($item AS $key2 => $item2){
$data[$key2][] = $item2;
}
}
print_r($data);
?>

PHP:配列の値を入れ替える関数


//テスト配列 
 $aaa = array();
 $aaa[0]["color"] = "red";
 $aaa[0]["image"] = "apple";
 $aaa[1]["color"] = "blue";
 $aaa[1]["image"] = "nasubi";
 $aaa[2]["color"] = "green";
 $aaa[2]["image"] = "hourensou";
 $aaa[3]["color"] = "yellow";
 $aaa[3]["image"] = "lemon";

//関数
//引数(対象配列,入替元,入替先)
 function SwapArray( $input, $nn, $mm ) {
    $val1 = $input[ $nn ] ;
    $val2 = $input[ $mm ] ;
    $input[ $nn ]= $val2;
    $input[ $mm ]= $val1;
    return $input;
 }

//test
 print_r( $aaa ) ;
 print "
"; $aaa = SwapArray ( $aaa , 1 ,2 ); print_r( $aaa ) ; print "
";
出力
Array
(
    [0] => Array
        (
            [color] => red
            [image] => apple
        )

    [1] => Array
        (
            [color] => blue
            [image] => nasubi
        )

    [2] => Array
        (
            [color] => green
            [image] => hourensou
        )

    [3] => Array
        (
            [color] => yellow
            [image] => lemon
        )

)

Array ( [0] => Array ( [color] => red [image] => apple ) [1] => Array ( [color] => green [image] => hourensou ) [2] => Array ( [color] => blue [image] => nasubi ) [3] => Array ( [color] => yellow [image] => lemon ) )
配列の[1]と[2]が入れ替わった

2011年6月12日日曜日

FaceBookの「いいねボタン」を10秒で設置する方法



ページやサイトごとに、
公式サイト(末尾に記載)から毎回作るのは、
ちょっと面倒なので、簡単スクリプトを作りました。

下記のコードをコピペするだけで、
設置したページのURLを自動で取得してくます。



↓動作例







■公式な情報はこちら
http://www.facebook-japan.com/iine.html
http://developers.facebook.com/docs/reference/plugins/like/


検索用タグ:JavaScript、ブログパーツ、blogparts、auto detect page url、検知

2011年6月3日金曜日

Operaで、特定のページが途中で開かなくなる



■症状:
・特定のページが開けない(重いページ?)というか、開いている途中で固まる。サイトやページによって うまく開けたり、開けなかったり


■原因:
・ブラウザのキャッシュの保存先を、外部ドライブに変更していて、そのドライブをPCから外した。そのためページを開いた際に、Operaが存在しないドライブにアクセスを試みたまま、動作しなくなる。


■失敗した試み
・「opera:config」で修正しようとしたが、 ⇒ 内部通信エラーとなって開けない。
・とあるサイトには「C:\Documnet ant Settings\ログインしているユーザー名\Application Data\Opera\Opera\profile\ 」を削除したらよいとかあるが、 ⇒ そんなファイルは見あたらなかった



■成功した解決方法:
(1)C:\Documents and Settings\ログインしているユーザー名\Application Data\Opera\Opera\
を開く。

(2)その中に、「 operaprefs.ini」というファイルがあるので、念のためバックアップをとったうえで、開く。

(3)「Cache Directory4=」で始まる行がある。そのイコールの右辺が、無効なドライブだったので、適切なドライブ、フォルダ名に変更して保存
 
(4)オペラを再起動