-
-
Save YaroslavB/d4b4821eba587c5208ea2ccd3b5d3bef to your computer and use it in GitHub Desktop.
Revisions
-
Kirill-Gorelov revised this gist
Aug 21, 2020 . 1 changed file with 9 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -190,15 +190,15 @@ function del_item_arr($array){//сюда приходит массив array( 'name' => 'б 2', 'price' => 1090 ), ); //сортировка по алфавиту по имени usort($data, function($a, $b){ return strcasecmp($a['name'], $b['name']); }); //сортировка по возврастанию по цене usort($data, function($a, $b){ return ($a['price'] - $b['price']); }); print_r($data); </pre> ?> -
Kirill-Gorelov revised this gist
Jun 9, 2020 . 1 changed file with 1 addition and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -445,17 +445,5 @@ function sorting( & $array ) } var_dump($array);
-
Kirill-Gorelov revised this gist
May 25, 2020 . 1 changed file with 10 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -253,10 +253,17 @@ function del_item_arr($array){//сюда приходит массив //Результат echo '<pre>'.print_r($result, true).'</pre>'; //и еще вариант с фильтрацией function filterElement($array, $name){ $filtered = array_filter( $array, function ($item) use($name){ return $item->getType() == $name; } ); return $filtered; } /**************** Сортировка массива в алфавитном порядке **************/ -
Kirill-Gorelov revised this gist
Jul 10, 2019 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -138,6 +138,12 @@ function del_item_arr($array){//сюда приходит массив } /*********** объединение двумерных массивов первый вариант **********/ $result = []; array_walk_recursive($rez, function ($item, $key) use (&$result) { $result[] = $item; }); /*********** объединение двумерных массивов второй вариант **********/ <?php //Enter your code here, enjoy! -
Kirill-Gorelov revised this gist
Jun 18, 2019 . 1 changed file with 54 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -365,32 +365,73 @@ function super_unique($array,$key) /***************************** первая буква из элементов массива *****************************/ $array = [ [ 'name' => 'Брянск' ], [ 'name' => 'Москва' ], [ 'name' => 'Можайск' ], [ 'name' => 'Барнуал' ], [ 'name' => 'Бобруйск' ], [ 'name' => 'Санкт-Петербург' ], [ 'name' => 'Дмитров' ], [ 'name' => 'Дубна' ], ]; # Сортируем по алфавиту asort( $array ); # Формируем массив разбитый на категории sorting( $array ); function sorting( & $array ) { # "Память" $memory = NULL; # Новый массив $sorting = array(); # Обходим массив foreach( $array as $key=>$item ) { # Получаем первую букву $letter = mb_substr( $item['name'], 0, 1, 'utf-8' ); # Если текущая буква не равна предыдущей if( $letter != $memory ) { # Заносим букву в "память" $memory = $letter; # Добавляем новый массив $sorting[$memory] = array(); } # Дополняем массив $sorting[$memory][$key] = $item; } # Назвачаем массив $array = $sorting; } var_dump($array); /**************************** json ****************************/ -
Kirill-Gorelov revised this gist
Jun 18, 2019 . 1 changed file with 29 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -362,6 +362,35 @@ function super_unique($array,$key) print_r ($tmp); /***************************** первая буква из элементов массива *****************************/ $data = [ [ 'name' => 'Брянск' ], [ 'name' => 'Москва' ], [ 'name' => 'Бобруйск' ], ]; usort($data, function ($v1, $v2) { return strcmp($v1['name'], $v2['name']); }); $letter = null; foreach ($data as $v) { $currentLetter = mb_substr($v['name'], 0, 1, 'utf-8'); if ($currentLetter !== $letter) { $letter = $currentLetter; echo "--- $letter ---", PHP_EOL; } echo $v['name'], PHP_EOL; } /**************************** json ****************************/ -
Kirill-Gorelov revised this gist
Jun 18, 2019 . 1 changed file with 18 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -344,6 +344,24 @@ function super_unique($array,$key) $uniquePids = array_unique(array_map(function ($i) { return $i['pid']; }, $b)); var_dump($uniquePids); /******************************* уникальные элементы ассоциативного массива ********************************/ $a = array ( 0 => array ( 'value' => 'America', ), 1 => array ( 'value' => 'England', ), 2 => array ( 'value' => 'Australia', ), 3 => array ( 'value' => 'America', ), 4 => array ( 'value' => 'England', ), 5 => array ( 'value' => 'Canada', ), ); $tmp = array (); foreach ($a as $row) if (!in_array($row,$tmp)) array_push($tmp,$row); print_r ($tmp); /**************************** json ****************************/ -
Kirill-Gorelov revised this gist
Jun 18, 2019 . 1 changed file with 25 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -318,7 +318,31 @@ function super_unique($array,$key) echo "unique*********************<br/>"; print_r(super_unique($arr,'titel')); ?> /****************************** достать уникальные значения из многомерного массива *****************************/ $b = array ( 0 => array ( 'id' => 1, 'pid' => 121, 'uuid' => 1, ), 1 => array ( 'id' => 2, 'pid' => 13, 'uuid' => 1, ), 2 => array ( 'id' => 5, 'pid' => 121, 'uuid' => 1, ) ); $uniquePids = array_unique(array_map(function ($i) { return $i['pid']; }, $b)); var_dump($uniquePids); /**************************** json -
Kirill-Gorelov revised this gist
Jun 10, 2019 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -320,4 +320,17 @@ function super_unique($array,$key) ?> /**************************** json ****************************/ Столкнулся с задачей. Из js получить json от сервера, распарсить и вывести. Все как обычно, но json не хотел распарсиваться. Была ошибка "неожиданный токен json" Проблема была простой, но потратил на нее кучу времени. Данные, которые я выводил содержали в себе строки в кавычках. И получалось что json был не валидным. Проблему решил следующим образом addslashes(json_encode($video,JSON_HEX_QUOT)); Константы json https://www.php.net/manual/ru/json.constants.php
-
Kirill-Gorelov revised this gist
Jun 3, 2019 . 1 changed file with 45 additions and 23 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,29 +17,6 @@ /*************** массив в файл и из файла ********************/ /************************************ Функция записи массива по строчно в файл ************************************/ @@ -56,6 +33,51 @@ function gomass($file, $massiv){ } /********************* еще одна ункция записи массива в файл *********************/ <pre> <?php function contextToString($context) { $export = ''; foreach ($context as $key => $value) { $export .= "{$key}: "; $export .= preg_replace(array( '/=>\s+([a-zA-Z])/im', '/array\(\s+\)/im', '/^ |\G /m' ), array( '=> $1', 'array()', ' ' ), str_replace('array (', 'array(', var_export($value, true))); $export .= PHP_EOL; } return str_replace(array('\\\\', '\\\''), array('\\', '\''), rtrim($export)); } $response = []; $response['result'] = ''; $response['result']['status'] = false; $response['result']['error'] = ''; $response['result']['error']['code'] = 'error_server_account'; $response['result']['error']['description'] = 'Обратитесь в службу поддержки'; $response['data'] = 'err'; print(contextToString($response)); ?> </pre> //output result: array( 'status' => false, 'error' => array( 'code' => 'error_server_account', 'description' => 'Обратитесь в службу поддержки', ), ) data: 'err' /****************** из одномерного массива в двумерный ***********/ -
Kirill-Gorelov revised this gist
May 12, 2019 . 1 changed file with 33 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -264,5 +264,38 @@ function abc($a,$b){ /********************** удаление дубликатов по ключу ***********************/ <?php function super_unique($array,$key) { $temp_array = []; foreach ($array as &$v) { if (!isset($temp_array[$v[$key]])) $temp_array[$v[$key]] =& $v; } $array = array_values($temp_array); return $array; } $arr=""; $arr[0]['id']=0; $arr[0]['titel']="ABC"; $arr[1]['id']=1; $arr[1]['titel']="DEF"; $arr[2]['id']=2; $arr[2]['titel']="ABC"; $arr[3]['id']=3; $arr[3]['titel']="XYZ"; echo "<pre>"; print_r($arr); echo "unique*********************<br/>"; print_r(super_unique($arr,'titel')); ?>
-
Kirill-Gorelov revised this gist
Aug 15, 2018 . 1 changed file with 37 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -229,3 +229,40 @@ function del_item_arr($array){//сюда приходит массив floor((strtotime(date('d.m.Y')) - strtotime($arUser['UF_COUNTER'])) / 86400) /**************** Сортировка массива в алфавитном порядке **************/ //автор не я $arr = array( 'Петя', 'Yury', 'Maxim', 'Юденок', 'Мыков', 'Obama', 'Артем', 'Янукович', 'Яша', 'Gerome' ); function abc($a,$b){ $la = mb_substr($a,0,1,'utf-8'); $lb = mb_substr($b,0,1,'utf-8'); if(ord($la) > 122 && ord($lb) > 122){ return $a > $b ? 1 : -1; } if(ord($la) > 122 || ord($lb) > 122) { return $a < $b ? 1 : -1; } } uasort($arr, 'abc'); // или usort(), если сохранение ключей не важно echo '<pre>'; print_r($arr); echo '</pre>'; -
Kirill-Gorelov revised this gist
Jul 3, 2018 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -224,3 +224,8 @@ function del_item_arr($array){//сюда приходит массив //Результат echo '<pre>'.print_r($result, true).'</pre>'; // Разница между двумя датами в днях floor((strtotime(date('d.m.Y')) - strtotime($arUser['UF_COUNTER'])) / 86400) -
Kirill-Gorelov revised this gist
Jun 26, 2018 . 1 changed file with 29 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -195,3 +195,32 @@ function del_item_arr($array){//сюда приходит массив var_dump($result); // array(2) { [0]=> array(2) { [0]=> string(1) "a" [1]=> string(1) "b" } [1]=> array(2) { [0]=> string(1) "b" [1]=> string(1) "c" } } /********************** Поиск в многомерном массиве по значению (не по ключу) **********************/ $out_data = array ( array("01_composita","Composita"), array("02_composita_p","Composita Plus"), array("03_contemporanea","Contemporanea"), array("04_epc","Epc"), array("05_hotel","Hotel"), array("06_plain_filomuro","Plait Filomuro"), array("07_pds","Pds"), array("08_soluzione","Soluzione"), array("09_teknoeuropa","Teknoeuropa"), array("10_telemako","Telemako"), array("08_soluzione","Telemako") ); //Ищем $needle = "08_soluzione"; //Собственно поиск $result = array_filter($out_data, function($innerArray){ global $needle; //return in_array($needle, $innerArray); //Поиск по всему массиву return ($innerArray[0] == $needle); //Поиск по первому значению }); //Результат echo '<pre>'.print_r($result, true).'</pre>'; -
Kirill-Gorelov revised this gist
Jun 21, 2018 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -86,6 +86,17 @@ function two_to_one($array){ $arrOut = iterator_to_array($iterator, true); return $arrOut; } // 3 способо, иногда нужно так function two_to_one($array){ $new = array(); foreach ($array as $key=>$val) { foreach ($val as $k=>$v) { $new[] = $v; } } return $new; } /************ удаление из одномерного массива по ключам ***************/ $arr = array('id' => 4, 'date_create' => '4.10.2013 20:47:52', 'name' => 'BCAA', 'depth_level' => 1, 'description' => null, 'searchable_content' => 'BCAA', 'code' => 'BCAA', 'detail_picture' => null); $delete_keys = array('description', 'searchable_content', 'code', 'detail_picture'); -
Kirill-Gorelov revised this gist
May 4, 2018 . 1 changed file with 22 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -162,4 +162,25 @@ function del_item_arr($array){//сюда приходит массив ); print_r($data); </pre> ?> /************** Удалить дубликаты из двумерного массива ***************/ $arr = array(array('a', 'b'), array('b', 'c'), array('a', 'b'), array('a', 'b')); $result = array_reduce($arr, function($a, $b) { static $stored = array(); $hash = md5(serialize($b)); if (!in_array($hash, $stored)) { $stored[] = $hash; $a[] = $b; } return $a; }, array()); var_dump($result); // array(2) { [0]=> array(2) { [0]=> string(1) "a" [1]=> string(1) "b" } [1]=> array(2) { [0]=> string(1) "b" [1]=> string(1) "c" } } -
Kirill-Gorelov revised this gist
Mar 26, 2018 . 1 changed file with 26 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -136,4 +136,30 @@ function del_item_arr($array){//сюда приходит массив } print_r($arr1); /***************************** сортировка по алфавиту в двумерном массиве ****************************/ <pre> $data = array ( array( 'name' => 'привет 1', 'price' => 200 ), array( 'name' => 'пока 2', 'price' => 100 ), array( 'name' => 'ж 2', 'price' => 150, 'rr' => array('dfgh', 'dfghj')), array( 'name' => 'а 2', 'price' => 110 ), array( 'name' => 'б 2', 'price' => 1090 ), ); usort ( $data, create_function ( '$a,$b', 'return ($a["name"] < $b["name"]);' ) ); print_r($data); </pre> ?> -
Kirill-Gorelov revised this gist
Mar 2, 2018 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,6 +40,23 @@ function object_from_file($filename) return $value; } /************************************ Функция записи массива по строчно в файл ************************************/ function gomass($file, $massiv){ // exit(); foreach($massiv as $value) // запись хорошего массива { $str.= "\n" .$value; } $fp = fopen($file, "a"); // Открываем файл в режиме записи $mytext = $str; // Исходная строка $test = fwrite($fp, $mytext); // Запись в файл fclose($fp); //Закрытие файла } /****************** из одномерного массива в двумерный ***********/ $array = Array('Аксессуары', 'Верхняя одежда', 'Для спорта', 'Нижнее белье', 'Обувь', 'Платье', 'Аксессуары2', 'Верхняя одежда2', 'Для спорта2', 'Нижнее белье', 'Обувь', 'Для девочек', 'Для мальчиков', 'Для новорожденных', 'Игрушки'); -
Kirill-Gorelov revised this gist
Dec 13, 2017 . 1 changed file with 33 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -86,4 +86,37 @@ function del_item_arr($array){//сюда приходит массив } return $array_new; } /*********** объединение двумерных массивов второй вариант **********/ <?php //Enter your code here, enjoy! $arr1 = array( array('id' => 57, 'fullName' => 'Иванов Иван Иваныч', /* rest of the fields */), array('id' => 250, 'fullName' => 'Сидоров Иван Иваныч', /* rest of the fields */), array('id' => 2530, 'fullName' => 'Петров Иван Иваныч', /* rest of the fields */), ); $arr2 = array( array('ids' => 57, 'age' => 50), array('ids' => 250, 'age' => 43), array('ids' => 2530, 'age' => 33), ); $arr1 = array_reduce($arr1, function (array $res, array $info) { $res[$info['id']] = $info; return $res; }, array()); foreach ($arr2 as $ageInfo) { $id = $ageInfo['ids']; if(array_key_exists($id, $arr1)) { //$arr1[$id] = array_merge($arr1[$id], $ageInfo); $arr1[$id]['age'] = $ageInfo['age']; } } print_r($arr1); ?> -
Kirill-Gorelov revised this gist
Oct 19, 2017 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -51,7 +51,24 @@ function parceArray(&$arr, $num = 5) { } echo '<pre>'; print_r(parceArray($array, 5)); /***************** из двумерного массива в одномерный *****************/ //1 способ function two_to_one($array){ $new = array(); foreach ($array as $key=>$val) { foreach ($val as $k=>$v) { $new[$k] = $v; } } return $new; } // 2 способ function two_to_one($array){ $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array)); $arrOut = iterator_to_array($iterator, true); return $arrOut; } /************ удаление из одномерного массива по ключам ***************/ $arr = array('id' => 4, 'date_create' => '4.10.2013 20:47:52', 'name' => 'BCAA', 'depth_level' => 1, 'description' => null, 'searchable_content' => 'BCAA', 'code' => 'BCAA', 'detail_picture' => null); $delete_keys = array('description', 'searchable_content', 'code', 'detail_picture'); -
Kirill-Gorelov revised this gist
Oct 17, 2017 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -52,4 +52,21 @@ function parceArray(&$arr, $num = 5) { echo '<pre>'; print_r(parceArray($array, 5)); /************ удаление из одномерного массива по ключам ***************/ $arr = array('id' => 4, 'date_create' => '4.10.2013 20:47:52', 'name' => 'BCAA', 'depth_level' => 1, 'description' => null, 'searchable_content' => 'BCAA', 'code' => 'BCAA', 'detail_picture' => null); $delete_keys = array('description', 'searchable_content', 'code', 'detail_picture'); $arr = array_diff_key($arr, array_flip($delete_keys)); // Only one line! print_r($arr); /************ удаление из двумерного массива по ключам ***************/ function del_item_arr($array){//сюда приходит массив $delete_keys = array('DEFAULT_VALUE', 'SORT', 'MULTIPLE'); // print_r($array); foreach ($array as $key => $value) { $array_new[] = array_diff_key($value, array_flip($delete_keys)); } return $array_new; } ?> -
Kirill-Gorelov revised this gist
Oct 3, 2017 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -41,4 +41,15 @@ function object_from_file($filename) } /****************** из одномерного массива в двумерный ***********/ $array = Array('Аксессуары', 'Верхняя одежда', 'Для спорта', 'Нижнее белье', 'Обувь', 'Платье', 'Аксессуары2', 'Верхняя одежда2', 'Для спорта2', 'Нижнее белье', 'Обувь', 'Для девочек', 'Для мальчиков', 'Для новорожденных', 'Игрушки'); function parceArray(&$arr, $num = 5) { $newArr = array(); foreach($arr as $i => $v) $newArr[floor($i / $num)]['key' . ($i++ % $num)] = $v; return $newArr; } echo '<pre>'; print_r(parceArray($array, 5)); ?> -
Kirill-Gorelov renamed this gist
Sep 7, 2017 . 1 changed file with 29 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,6 @@ <?php /****************** удаляем из массива ******************/ //массив из которого нужно удалить $letters = array('(', ')', '[', ']', '{', '}','h', 'r','ff'); @@ -12,4 +14,31 @@ //если нужно удалить символы, которые в массиве $no_delete if(in_array($char, $no_delete)) unset($letters_new[$key]); } /*************** массив в файл и из файла ********************/ /****************** pзапись массива в файл ***************/ function object2file($value, $filename) { $str_value = serialize($value); $f = fopen($filename, 'w'); fwrite($f, $str_value); fclose($f); } /***************** чтение массива из файла *******************/ function object_from_file($filename) { $file = file_get_contents($filename); $value = unserialize($file); return $value; } ?> -
Kirill-Gorelov revised this gist
Sep 7, 2017 . 2 changed files with 15 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ <?php //массив из которого нужно удалить $letters = array('(', ')', '[', ']', '{', '}','h', 'r','ff'); //массив данных, которые не трогаем $no_delete = array('(', ')', '[', ']', '{', '}'); foreach($letters_new as $key => $char){ // если символ не в "запретном списке" - удалить его из массива if(!in_array($char, $no_delete)) unset($letters_new[$key]); //если нужно удалить символы, которые в массиве $no_delete if(in_array($char, $no_delete)) unset($letters_new[$key]); } ?> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +0,0 @@ -
Kirill-Gorelov created this gist
Sep 7, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ <?php ?>