Skip to content

Instantly share code, notes, and snippets.

View imcarvalho's full-sized avatar
🦄

Inês Carvalho imcarvalho

🦄
View GitHub Profile
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": [
"comment",
"constant",
"keyword",
"markup.italic",
"meta.selector",
"storage.modifier",
@imcarvalho
imcarvalho / search_multidimensional_array_by_key.php
Created February 14, 2017 16:08
Simple recursive function to search a multidimensional array by a key, and return all the values of that key
<?php
class SearchMultidimensionalArray
{
public static function searchByKey($array, $needle, &$results) {
if (is_array($array)) {
foreach ($array as $item) {
if (isset($item[$needle])) {
$results[] = $item[$needle];
continue;
@imcarvalho
imcarvalho / install_php_extensions_mac_mamp.md
Last active May 10, 2018 10:46
Install extensions on MAMP 3.5 and Mac OSX 10.11 tutorial

I'm using PHP 5.6.10, and trying to install the memcache extension. You can adapt this to other PHP versions and to other extensions, of course 😄

  • Download the version of PHP you're using from php.net.
  • At /Applications/MAMP/bin/php/php5.6.10, create a directory named include.
  • Inside /Applications/MAMP/bin/php/php5.6.10/include (your newly created folder), untar the php file you downloaded from php.net.
  • For me, it produced a folder named "php-5.6.10". Rename it to "php". Now you'll have this structure: /Applications/MAMP/bin/php/php5.6.10/include/php
  • Go to that folder on terminal, and run ./configure
  • Then, go to /Applications/MAMP/bin/php/php5.6.10/include/php/bin
  • Run, for instance: sudo /Applications/MAMP/bin/php/php5.6.10/bin/pecl install memcache
  • Afterwards, edit your php.ini file (/Applications/MAMP/bin/php/php5.6.10/conf/php.ini), and add the line extension=memcache.so
<?php
class JsonResponse implements ResponseInterface
{
/**
* Return a success response.
* Set the header:
* Content-Type: application/json
*
* @param array $body the body of the response
@imcarvalho
imcarvalho / inQuery.php
Last active November 10, 2015 08:28
Compose an IN for MySQL on PHP.
<?php
/**
* Since PDO doesn't support arrays for the IN natively
* You use the result in the SQL query string as IN($inQuery)
* and $inValues as the $params for the PDO function
* ['A1' => 'first value to find', 'A2' => 'second value to find']
*
* @param array $toFind
* @param string $queryVariableName