Search This Blog

22 October 2021

PHP ARRAY

 GROUP BY ARRAY AND INCLUDE ROW VALUES TO THIS ARRAY

 public function getProducts($id='')

{

$this->db->select("pi.image as image,p.product_name,p.id as productId,p.product_code,p.price,p.product_size,c.c_name as category_name,p.status");
$this->db->from("products as p");
$this->db->join('product_images as pi','pi.product_id=p.id','left');
$this->db->join("category as c", "c.id=p.category_id", "left");
$this->db->where('p.status', 1);
    if(!empty($id)){
        $this->db->where('p.id',$id);
      }
$results = $this->db->get()->result();
$productArray = $imageArray = array();
        foreach($results as $key=> $row)
 
{
                 $productId = $row->productId;
                  if (!isset($productArray[$productId])) {
                 $productArray[$productId] = (array) $row;
                 $productArray[$productId]['images'] = [];
             }
           $productArray[$productId]['images'][] = $row->image;
}
return $productArray;
}


   OutPut :



GROUPBY ARRAY LIKE CATEGORY


foreach($permissions as $row)
{
   
    $name = $row['name'] ?? 'N/A';

    $categoryArray[$name][] = $row;

    if (!isset($
categoryArray[$name])) {
       $
categoryArray[$name] = [];
     }

}

Output : like 

Fruits:
    0->Apple
    1->orange
    2->mango
Flowers:
   0->jasmine
   1->sunflower


 

Jquery or Javascript Start Exam Time

 <script> function startTimer() {      var date = "<?php echo $date ?>"; // dynamic date      var time = "<?...