Array Functions

Array Push

File Name :

public function ittutorial()
{
$data=array();
$this->db->select('*');
$this->db->from('tutorial');
$qry = $this->db->get();
$data_result = $qry->result();
foreach($data_result as $row)
{
// $title_list['pid'][] = array('pid'=>$row->pid);
$doc_array[] = $row->pid;
}
// echo "<pre>";print_r($doc_array); echo "</pre>";

/*
$arr = array();
for($i=0;$i<count($data_result); $i++)
{
array_push($arr, $data_result[$i]->pid);
}
*/

if(!in_array($uid, $doc_array))
{
redirect('http://ittutorial.in/login');
}

}

Array Push

File Name :

$this->db->select('ID');
$this->db->from('itechxpert');
$this->db->where("Department_ID",$dept_id);
$qry = $this->db->get();
$res = $qry->result();

$ar= array();
for($i=0;$i<count($res); $i++)
{
array_push($ar,$res[$i]->ID);
}
$this->db->select('*');
$this->db->from('itechxpert');
$this->db->where_in('Tech_id', $ar);
$query3 = $this->db->get();
$qry3 = $this->db->last_query();
return $query3->result();

Array Push

File Name :

<?php
$a=array("Kalam","mahtab");
array_push($a,"vicky","chotu");
print_r($a);
?>

File Name :

$data['arr']=array('list'=>'');

// insert element to array
for (ix = 0; ix <= 10; $ix++) {
$data['arr']=array('list'=>$i);
}

//show output
foreach($arr As $key => $value )
{
echo $value . ",";
}

How to convert object into array.

File Name :

$myObject = new MyClass;
$myObject->id = 01;
$myObject->name= "Sana";
$myObject->age= "2";
$newArray = (array) $myObject;
print_r($newArray);

array_column() Function

it return single column of table.

File Name :

<?php
// An array that represents a possible record set returned from a database
$arr = array(
array(
'id' => 1,
'first_name' => 'mahtab',
'last_name' => 'alam',
),
array(
'id' => 2,
'first_name' => 'Sana',
'last_name' => 'mahtab',
),
array(
'id' => 3,
'first_name' => 'mahira',
'last_name' => 'Bano',
)
);

$last_names = array_column($arr, 'last_name');
print_r($last_names);
?>





Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here