Print variables Up value - arrays

The print_r returns the following value:
[cobrancas] => Array
(
[0] => stdClass Object
(
[id] => 749205
[nossonumero] => 3189028
[dataemissao] => 1395284400
[datavencimento] => 1395370800
[datapagamento] => 1395284400
[dias_vencidos] => 788
[mora] => 0.23225806451613
[multa] => 1.8
[valor] => 90.00
[valorpago] => 88.57
[valordesconto] => 0.00
[jurosmora] => 0.00
[banco] => 33
[agencia] => 1525
[dac_agencia] => 0
[conta] => 013000045
[dac_conta] => 2
[carteira] => 201
[nome_empresa] => STOCK MIDIA INF. LTDA
[cod_cedente] => 1640348
)
But as I know it gives me values ​​of up to [ 50 ] up. How do I know the print me just [VALOR ] above 100.00 ???
$Arr = count($cliente->cobrancas);

Related

How to iterate this array to match all possible connections

As a person that couldn't grasp recursion, I'm getting an array that has unlimited depth on parent <> child id links. This is a category list from an ecommerce platform (Shopee). And I'm trying to build a relationship list between all the categories and subcategories from the array below.
How to get this
Women's Clothing -> Tshirt -> Trending
-> Promotion
Shoes -> Hiking Shoe -> Winter Shoe
From the array below
$category = Array(
[0] => Array
(
[category_id] => 16
[parent_id] => 0
[category_name] => Women's Clothing
[has_children] => 1
)
[1] => Array
(
[category_id] => 18
[parent_id] => 16
[category_name] => Tshirt
[has_children] => 1
)
[2] => Array
(
[category_id] => 901
[parent_id] => 18
[category_name] => Trending
[has_children] => 0
)
[3] => Array
(
[category_id] => 23
[parent_id] => 0
[category_name] => Shoes
[has_children] => 1
)
[4] => Array
(
[category_id] => 100
[parent_id] => 23
[category_name] => Hiking Shoe
[has_children] => 1
)
[5] => Array
(
[category_id] => 120
[parent_id] => 100
[category_name] => Winter Shoe
[has_children] => 0
)
[6] => Array
(
[category_id] => 1400
[parent_id] => 18
[category_name] => Promotion
[has_children] => 0
)
)
You could first group the items by their parent key, and then perform a depth-first traversal through the data:
function dfs(&$childrenfor, $id, $path) {
if (isset($childrenfor[$id])) {
foreach($childrenfor[$id] as $item) {
yield from dfs($childrenfor, $item["category_id"], [...$path, $item["category_name"]]);
}
} else {
yield $path;
}
}
// first group the items by parent key
foreach ($category as $item) {
$childrenfor[$item["parent_id"]][] = $item;
}
// ...then use depth-first traversal to collect the root-to-leaf paths in the tree
$result = [...dfs($childrenfor, 0, [])];
The $result would have the following for your example data:
[
["Women's Clothing", "Tshirt", "Trending"],
["Women's Clothing", "Tshirt", "Promotion"],
["Shoes", "Hiking Shoe", "Winter Shoe"]
]
I guess you can take it from there to generate a format that suits you.

How to print associative array in codeigniter

my controller is : **
public function getdatewiseOrder()
{
$cid = $this->input->post('cid');
$startdate = strtotime($this->input->post('start_date'));
$enddate = strtotime($this->input->post('end_date'));
$order = $this->model_reports->getdatewiseOrder($cid, $startdate, $enddate);
$x = 0;
foreach ($order as $key => $value) {
$item[$x] = $this->model_reports->getorderItem($value['id']);
$x = $x + 1;
}
$this->data['order'] = $order;
$this->data['item'] = $item;
$this->render_template('reports/leser_report', $this->data);
}
for check : after print_r of item variable i get data in this format:
Array (
[0] => Array (
[0] => Array (
[id] => 188
[order_id] => 93
[product_name] => 2
[barcode_nos] =>
[barcode_no] =>
[qtykg] => 1
[qtypcs] => 2
[unit] =>
[rate] => 234
[amount] => 234.00
[tax_id] =>
[timestamp] => 2018-10-30 12:51:10
)
)
[1] => Array (
[0] => Array (
[id] => 191
[order_id] => 96
[product_name] => Small
[barcode_nos] =>
[barcode_no] =>
[qtykg] => 5
[qtypcs] => 5
[unit] =>
[rate] => 100
[amount] => 500.00
[tax_id] =>
[timestamp] => 2018-11-15 09:49:41
)
[1] => Array (
[id] => 192
[order_id] => 96
[product_name] => Medium
[barcode_nos] =>
[barcode_no] =>
[qtykg] => 5
[qtypcs] => 5
[unit] =>
[rate] => 90
[amount] => 450.00
[tax_id] =>
[timestamp] => 2018-11-15 09:49:43
)
)
[2] => Array (
[0] => Array (
[id] => 206
[order_id] => 105
[product_name] => Small
[barcode_nos] =>
[barcode_no] =>
[qtykg] => 2
[qtypcs] => 50
[unit] =>
[rate] => 100
[amount] => 200.00
[tax_id] =>
[timestamp] => 2018-11-15 13:38:47
)
)
[3] => Array (
[0] => Array (
[id] => 207
[order_id] => 106
[product_name] => Medium
[barcode_nos] =>
[barcode_no] =>
[qtykg] => 50
[qtypcs] => 100
[unit] =>
[rate] => 15
[amount] => 750.00
[tax_id] =>
[timestamp] => 2018-11-15 13:40:12
)
)
)
I have two tables order and order_item and i am fetch data from both
for fetching data from order table i use
$order = $this->model_reports->getdatewiseOrder($cid, $startdate,
$enddate);
for fetching data from order_item i am using
$item[$x] = $this->model_reports->getorderItem($value['id']);
inside foreach loop
I want output in this format
enter image description here

combine two php array for json encode

Presently m working with CakePhp..i got some problem with combining two array and prepare for a json encoded array.. i used array_merge() property but its not working.. how can i encoded both of these two array..
M doing like this :
return json_encode(array_merge ($product_list,$price_list));
i have two php array as follows :
array 1:
Array
(
[0] => Array
(
[PriceList] => Array
(
[price_id] => 2
[price_name] => abc
[date_time] => 2015-07-06 16:22:56
[dealer_type] => Dealer
[purpose] => dealer
[status] => ACTIVE
)
)
[1] => Array
(
[PriceList] => Array
(
[price_id] => 3
[price_name] => xyz
[date_time] => 2015-07-06 16:22:56
[dealer_type] => Dealer
[purpose] => dealer
[status] => ACTIVE
)
)
)
array 2:
Array
(
[0] => Array
(
[Product] => Array
(
[cat_id] => 1
[subcat_id] => 3
[brand_id] => 1
[p_code] => PP12567
[name] => akai
[model_no] =>
[specification] => color tv
[color] =>
[quality] =>
[size] =>
[p_unavail] => 1
[demo_avail] => 0
[brochure] =>
[status] => active
)
[ProductPrice] => Array
(
[id] => 154
[p_code] => PP12567
[price_id] => 1
[quantity] => 233
[purchase_price] => 344.00
[selling_price] => 44.00
[discount_price] => 33.00
[tax] => 5.00
[datetime] => 2015-07-23 15:47:11
)
[ProductSubCategory] => Array
(
[subcat_id] => 3
[cat_id] => 1
[subcat_name] => samsung
[status] => active
)
[ProductCategory] => Array
(
[cat_id] => 1
[cat_name] => Electronics
[cat_type] => Product
[status] => active
)
)
[1] => Array
(
[Product] => Array
(
[cat_id] => 1
[subcat_id] => 4
[brand_id] => 1
[p_code] => PBC-676767
[name] => music
[model_no] => 33
[specification] =>
[color] =>
[quality] =>
[size] =>
[p_unavail] => 0
[demo_avail] => 0
[brochure] =>
[status] => active
)
[ProductPrice] => Array
(
[id] => 156
[p_code] => PBC-676767
[price_id] => 1
[quantity] => 767
[purchase_price] => 54.00
[selling_price] => 55.00
[discount_price] => 22.00
[tax] => 3.00
[datetime] => 2015-07-23 15:47:11
)
[ProductSubCategory] => Array
(
[subcat_id] => 4
[cat_id] => 1
[subcat_name] => sony
[status] => active
)
[ProductCategory] => Array
(
[cat_id] => 1
[cat_name] => Electronics
[cat_type] => Product
[status] => active
)
)
)
how to combine these two array into one and encoded into a json array..
You have to use array_merge but not directly on array1 and array2:
$toEncodeArray = [array_merge ($array1[0], $array2[0])] ;
If you only want the associative array (without the wrapping array), simply do:
$toEncodeArray = array_merge ($array1[0], $array2[0]) ;

print array multidimensional values

i I have a problem to print array .I received this array of web services by nusoap
How can I display the values ​​of this multidimensional array. I worked with foreach, I could not do it., Please explain with an example. Thanks
my array:
Array ( [Result] => Array ( [Root] => Array ( [row] => Array ( [0] => Array ( [!R] => 0 [!C1] => 300064 [!C2] => name1 [!C3] => 1287744941 [!C4] => 798 [!C5] => 1338/06/29 [!C6] => [!C7] =>name2 [!C8] =>name2 91 ) [1] => Array ( [!R] => 19 [!C1] => 300064 [!C2] => name1 [!C3] => 1287744941 [!C4] => 798 [!C5] => 1338/06/29 [!C6] => [!C7] =>name2 [!C8] =>name2 92 ) [2] => Array ( [!R] => 38 [!C1] => 300064 [!C2] => name1 [!C3] => 1287744941 [!C4] => 798 [!C5] => 1338/06/29 [!C6] => [!C7] =>name2 [!C8] =>name2 93 ) [3] => Array ( [!R] => 57 [!C1] => 300064 [!C2] => name1 [!C3] => 1287744941 [!C4] => 798 [!C5] => 1338/06/29 [!C6] => [!C7] => name3 [!C8] => name3 ) ) ) ) )

CakePHP: Using the same layout

In my "CouponsController.php", I have the following 2 functions:
public function index() {
$this->set('coupons', $this->Coupon->find('all'));
}
public function restaurants() {
$this->set('coupons', $this->Coupon->findBycategory_id('1'));
$this->render("index");
}
Basically, I want index function to return all coupons, and restaurants to return just category 1 (but I want to use the same view file).
I end up getting this errror:
Notice (8): Undefined index: Coupon [APP/View/Coupons/index.ctp, line 16]
It's because of how the array is returned for each of them. Here is my VIEW file and the results for each page:
Coupons/index.ctp:
foreach ($coupons as $c) {
print_r($c);
}
INDEX function:
Array ( [Coupon] => Array ( [id] => 1 [vendor_id] => 1 [category_id] => 1 [title] => $10 For Whatever [price] => 10.00 [value] => 20.00 [start_at] => 2012-02-07 12:03:00 [end_at] => 2012-02-29 12:03:05 [details] => Test [terms] => Test [mini_views] => 0 [large_views] => 0 [created] => 2012-02-08 12:03:12 ) ) Array ( [Coupon] => Array ( [id] => 2 [vendor_id] => 2 [category_id] => 2 [title] => Test [price] => 100.00 [value] => 200.00 [start_at] => 0000-00-00 00:00:00 [end_at] => 0000-00-00 00:00:00 [details] => [terms] => [mini_views] => 0 [large_views] => 0 [created] => 2012-02-08 12:14:03 ) )
RESTAURANTS function:
Array ( [id] => 1 [vendor_id] => 1 [category_id] => 1 [title] => $10 For Whatever [price] => 10.00 [value] => 20.00 [start_at] => 2012-02-07 12:03:00 [end_at] => 2012-02-29 12:03:05 [details] => Test [terms] => Test [mini_views] => 0 [large_views] => 0 [created] => 2012-02-08 12:03:12 )
Well it's just how cakephp returns it, a turnaround would be
foreach ($coupons as $coupon) {
$c = $coupon;
if (isset($coupon["Coupon"])) { // if is set index in array ["Coupon"] {
$c = $coupon["Coupon"];
}
print_r($c);
}
or
public function restaurants() {
$params = array('conditions' => array('Coupon.category_id' => 1));
$this->set('coupons', $this->Coupon->find('all', $params));
$this->render("index");
}

Resources