Web Development & WordPress

JSON to php object and array

Code:

<?php
class StudentInfo{
    public $name;
    public $age;
    private $mobileNum;
    public  function setMobileNum($mobileNum){
        $this->mobileNum=$mobileNum;
    }
    public function getMobileNum(){
        return $this->mobileNum; 
    }
}
$student = new StudentInfo();
$student -> name ="Tommy Jones";
$student -> age =45;
print_r($student);
$student->setMobileNum('11111111');
echo "<br>";
print_r($student);
$jsonEncoded=json_encode($student);
echo "<br>";
print_r($jsonEncoded);
$jsonDecoded=json_decode($jsonEncoded);
echo "<br>";
print_r($jsonDecoded);
$jsonDecodedArray=json_decode($jsonEncoded,true);
echo "<br>";
print_r($jsonDecodedArray);
?>
Continue reading “JSON to php object and array”
Web Development & WordPress

PHP Object to JSON

Only Public ones will be converted

Code:

<?php 
class studentInfo{
    public $name;
    public $age;
    private $mobileNum;
public function setMobileNum($mobileNum){
    $this->mobileNum=$mobileNum;
}
public function getMobileNum(){
    return $this->mobileNum;
}


}
$student = new studentInfo();
$student->name= "Tom hanks";
$student->age = 45;
 $student->setMobileNum('11111111');
//echo $student->getMobileNum();
echo json_encode($student);
?>
Continue reading “PHP Object to JSON”
Web Development & WordPress

isset(), empty() and is_numeric() in PHP

CODE:

<?php

$studentNum=0;
if(isset($studentNum)){
echo "value is set ";
}else{
    echo "value not set";
}
echo "<br>";
if(empty($studentNum)){
    echo "value is empty";
}else{
    echo "value not empty";
}
echo "<br>";
if(isset($studentNum) && (is_numeric($studentNum) || $studentNum !='')){
    echo "there is value and not empty";
}else{
    echo " not set or empty";
}
?>

OUTPUT:

value is set
value is empty
there is value and not empty
Web Development & WordPress

Associative array to JSON or Serialised conversion : PHP

Code:

<?php
$customer= [
"name"=>"Tommy Jason",
"age" => 45,
"sex" => "Male",
"location" => "USA"
];
print_r($customer);
echo "Serialized: <br>";
$serializedCustomer =serialize($customer);
echo $serializedCustomer;
echo "<br>";
echo "Unserialized: <br>";
$unserializedCustomer =unserialize($serializedCustomer);
print_r($unserializedCustomer);
echo "<br>";
echo "JSon Encoded<br>";
echo $jsonEncoded = json_encode($customer);
echo "<br>";
echo "Json Decoded --converted to object <br>";
$jsonDecoded= json_decode($jsonEncoded);
print_r($jsonDecoded);
echo "<br>Json Decoded --converted to Array <br>";
$jsonDecoded= json_decode($jsonEncoded,true);
print_r($jsonDecoded);
echo "<br>";

?>
Continue reading “Associative array to JSON or Serialised conversion : PHP”
Web Development & WordPress

PHP: Multidimensional Array and to show its value

Code:

<?php
$students=[
    '12'=>'Tom',
    '13'=>'Shib',
    '14'=>[
        '12'=>'Tom Spanish',
        '13'=>'Shib Spanish'
    ]
];
var_dump($students);
echo "<br>";

print_r($students);
echo "<br>";

echo $students["14"]["13"];
echo "<br>";
$food=array(
    "vegetables" => "tomato,potato",
    "frutis" => "apple, banana",
    "drinks" => array(
        "soft"=>"coke,fanta",
        "beverage" => "x,y,z",
    )
);

print_r($food);
echo "<br>";
echo $food["drinks"]["soft"];
?>
Continue reading “PHP: Multidimensional Array and to show its value”
Web Development & WordPress

Resolving WP Touch Pro Mobile View Conflict with W3 Total Cache: Fixing Desktop Cache Display Issue

If you are using both the W3 Total Cache and WP Touch Pro plugins for optimizing your site’s performance and mobile view respectively, you may encounter a conflict where WP Touch Pro stops displaying the mobile view and instead shows the cached desktop version.

Here is the Solution

Continue reading “Resolving WP Touch Pro Mobile View Conflict with W3 Total Cache: Fixing Desktop Cache Display Issue”
Web Development & WordPress

Add Social Icons at the end of blog post in Smart Theme v3 by Optimizepress

If you are using Smart Theme V3 by Optimizepress and you are searching to add some basic social icons at the end of blog post ( which you edited using Optimizepress builder), then use the code i shared here. It will be looked like this ( almost similar)

Continue reading “Add Social Icons at the end of blog post in Smart Theme v3 by Optimizepress”