<?php
$string = "Anna";
$strRawData = strtolower($string);
$arrRawData = str_split($strRawData);
$strRevData = implode('', array_reverse($arrRawData));
if ($strRawData == $strRevData) {
print_r("Yes, karena kata '$strRawData' ketika dibalik sama saja yaitu '$strRevData'");
} else {
print_r("No, karena kata '$strRawData' ketika dibalik tidak sama yaitu '$strRevData'");
}
4. query database
/* TABLE */
CREATE TABLE IF NOT EXISTS `docs` (
`id` int(6) unsigned NOT NULL,
`nama` varchar(200) NOT NULL,
`bulan` varchar(200) NOT NULL,
`value` bigint(15) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;
/* INSERT */
INSERT INTO `docs` (`id`, `nama`, `bulan`, `value`) VALUES
('1', 'ANTON', 'JANUARY', '100000'),
('2', 'ANTON', 'JANUARY', '250000'),
('3', 'ANTON', 'FEBRUARY', '300000'),
('4', 'ANTON', 'FEBRUARY', '100000'),
('5', 'DIAN', 'FEBRUARY', '10000');
/* QUERY */
SELECT A.NAMA, IF(B.VALUE IS NULL, 0, B.VALUE) JANUARY, IF(C.VALUE IS NULL, 0, C.VALUE) FEBRUARY
FROM ( SELECT NAMA
FROM docs
) AS A
LEFT JOIN (SELECT NAMA, sum(value) value, bulan
FROM docs
where bulan = 'JANUARY'
) AS B
ON A.NAMA=B.NAMA
LEFT JOIN ( SELECT NAMA, sum(value) value, bulan
FROM docs
where bulan = 'FEBRUARY'
) AS C
ON A.NAMA=C.NAMA
GROUP BY A.NAMA
ORDER BY A.NAMA DESC