try:
1/0
except Exception:
print('произошла ошибка, ну и пофиг')
package MyDataParser
import (
"encoding/json"
"io"
)
type Parser interface {
DecodeJSON(r io.Reader) error
}
func (p *MyStruct) DecodeJSON(r io.Reader) error {
return json.NewDecoder(r).Decode(&p)
}
type MyStruct struct {
Success int `json:"success"`
Return struct {
Funds struct {
Ltc int `json:"ltc"`
Nvc float64 `json:"nvc"`
Ppc int `json:"ppc"`
} `json:"funds"`
FundsInclOrders struct {
Ltc int `json:"ltc"`
Nvc float64 `json:"nvc"`
Ppc int `json:"ppc"`
} `json:"funds_incl_orders"`
Rights struct {
Info int `json:"info"`
Trade int `json:"trade"`
Withdraw int `json:"withdraw"`
} `json:"rights"`
TransactionCount int `json:"transaction_count"`
OpenOrders int `json:"open_orders"`
ServerTime int `json:"server_time"`
} `json:"return"`
}
Ну юзать как-то вот так.
var myData MyStruct
res, err := client.Get(uri)
err = posts.DecodeJSON(res.Body)
,,,
<?php
$items = [
['ID'=>35, 'menu_item_parent'=>0],
['ID'=>38, 'menu_item_parent'=>35],
['ID'=>36, 'menu_item_parent'=>35],
['ID'=>39, 'menu_item_parent'=>36],
['ID'=>40, 'menu_item_parent'=>39],
['ID'=>41, 'menu_item_parent'=>39],
['ID'=>37, 'menu_item_parent'=>0],
];
function find_childrens($items, $parentItem) {
$ret = [];
foreach($items as $item) {
if ($item['menu_item_parent'] == $parentItem['ID']) {
$treeItem = $item;
$treeItem['subitems'] = find_childrens($items, $item);
$ret[] = $treeItem;
}
}
return $ret;
}
$tree = [];
foreach($items as $item) {
if ($item['menu_item_parent'] == 0) {
$treeItem = $item;
$treeItem['subitems'] = find_childrens($items, $item);
$tree[] = $treeItem;
}
}
echo '<pre>';
print_r($tree);
echo '</pre>';
echo '<hr>';
function printer($treeItem, $level) {
if ($level) echo str_repeat('--', $level);
echo $treeItem['ID'].'<br>';
if ($treeItem['subitems']) {
foreach($treeItem['subitems'] as $subItem) {
printer($subItem, $level+1);
}
}
}
foreach($tree as $treeItem) printer($treeItem, 0);
Array
(
[0] => Array
(
[ID] => 35
[menu_item_parent] => 0
[subitems] => Array
(
[0] => Array
(
[ID] => 38
[menu_item_parent] => 35
[subitems] => Array
(
)
)
[1] => Array
(
[ID] => 36
[menu_item_parent] => 35
[subitems] => Array
(
[0] => Array
(
[ID] => 39
[menu_item_parent] => 36
[subitems] => Array
(
[0] => Array
(
[ID] => 40
[menu_item_parent] => 39
[subitems] => Array
(
)
)
[1] => Array
(
[ID] => 41
[menu_item_parent] => 39
[subitems] => Array
(
)
)
)
)
)
)
)
)
[1] => Array
(
[ID] => 37
[menu_item_parent] => 0
[subitems] => Array
(
)
)
)
====================================================
35
-- 38
-- 36
---- 39
------ 40
------ 41
37
<?php
$array = array(
[
'id' => '1',
'user_id' => 1,
'child' => [
[
'id' => 1,
'item_id' => 1,
'project_id' => 3
],
[
'id' => 2,
'item_id' => 2,
'project_id' => 0
]
]
]
);
var_dump(array_filter($array[0]['child'], function($v, $k) {
return $k == 'project_id' && $v != 0;
}, ARRAY_FILTER_USE_BOTH));
array(1) {
[0]=>
array(3) {
["id"]=>
int(1)
["item_id"]=>
int(1)
["project_id"]=>
int(3)
}
}
$fullarray = [.....]; //Массив с данными
$fields = ['product_id','name','group_id','manufacturer','fullname','code'];
$db = Yii::$app->db;
$sql = $db->queryBuilder->batchInsert(self::tableName(), $fields, $fullarray);
$product_insert_count = $db->createCommand($sql . ' ON DUPLICATE KEY UPDATE name = VALUES(name), group_id = VALUES(group_id), manufacturer = VALUES(manufacturer), fullname = VALUES(fullname), code = VALUES(code)')->execute();
var history = []
$("input[class='test']").on('input', function(){
history.push(this.value)
});
/domain/public_html/yii hello/index
php /domain/public_html/yii hello/index
/domain/public_html/yii hello/index
/usr/bin/php ~/domain/public_html/console/hello/index
php /domain/public_html/ yii hello/world
Yii::$app->errorHandler->errorAction = 'admin/default/error';
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction'
]
];
}
Items::updateAll(['price' => new \yii\db\Expression('price * 1.1')]);
Items::updateAll(['price' => new \yii\db\Expression('price * 0.9')]);
public static function getMenuList(){
$root = self::findOne(2); //2 это id root элемента
$leaves = $root->getChildren()->with('children')->all();
return \yii\helpers\ArrayHelper::toArray(
$leaves,
[
'common\models\Menu'=>[ //namespace модели
'label'=>'name',
'items'=> function($model){
return \yii\helpers\ArrayHelper::toArray(
$model->children,
[
'common\models\Menu'=>[
'label'=>'name',
]
]
);
},
]
]
);