Posted on

## What Better Assignment Than Fibonacci?

Since I am finished with the beginning into to PHP videos I found it imperative to do a stream putting everything together and showing you how easy it is to write an app. In today’s live stream I create a Fibonacci app, for those who are not familiar with the Fibonacci sequence there is a great wiki here. In this application I demonstrate variables, control flow logic, exception handling, and function design. All my code can be seen on my Github here or you can view it below in text or on video

``````<?php
\$input = '';
\$running = true;
while(\$running){
try{
getInput(\$input);
echo calculateFib(\$input) . "\n";
}
catch(Exception \$e){
echo "Message: {\$e->getMessage()}";
}
}
function getInput(&\$input){
};
function calculateFib(\$input){
if(intval(\$input) < 0){
throw new Exception("Input must be greater than zero! \n");
}
elseif(\$input === 'q' || \$input === 'Q'){
exit();
}
if(intval(\$input) === 0 || intval(\$input) === 1){
return 1;
}
else{
return calculateFib(\$input-1) + calculateFib(\$input - 2);
}
};
?>
``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.5515649,"math_prob":0.92232543,"size":1214,"snap":"2023-40-2023-50","text_gpt3_token_len":309,"char_repetition_ratio":0.1214876,"word_repetition_ratio":0.0,"special_character_ratio":0.29983526,"punctuation_ratio":0.13761468,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9837446,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-30T09:44:05Z\",\"WARC-Record-ID\":\"<urn:uuid:93b52817-7b35-47fc-9a00-3098f508c39d>\",\"Content-Length\":\"71972\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:de6a3e75-6f6a-4faf-a331-d9a13a4856b4>\",\"WARC-Concurrent-To\":\"<urn:uuid:70f6fe1e-701b-44ef-9e34-a37c3a9ae07a>\",\"WARC-IP-Address\":\"143.198.188.191\",\"WARC-Target-URI\":\"https://jyroneparker.com/tag/fibonacci/\",\"WARC-Payload-Digest\":\"sha1:2LKL4QLVUBE7QIASUBAF6PA7PJDBJKMD\",\"WARC-Block-Digest\":\"sha1:UDI25QB46C2S4WJVBAPSRMTIGJPGFNKN\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233510671.0_warc_CC-MAIN-20230930082033-20230930112033-00504.warc.gz\"}"}